I am new and I am having trouble with this on steps 2 and 3. Can anyone help me out here?
1. Write a shell script that asks the user to input the name of a file. The shell
script then tests to see if that file exists, if the file exists and it
is owned by the user the shell echos "The File is there and you own it".
2. If the file is not found, then the shell script calls a function and passes
the first argument to the function "The File Was Not found, Please try Again"
which is then echoed to the user and
another argument is passed to the function "You entered [filename]" which is
also echoed to the user showing the value of the filename variable,
the function then exits with an exit value of 10.
3. If the file is found, but is not owned by the user the shell script calls the
same function and passes the argument to the function "The File Was found,
but you do not own it. Please try Again" and another argument is passed to the
function "You entered [filename]" which is also echoed to the user,
the function then exits with an exit value of 10.
Code:
#!/bin/bash
echo -n "Enter a file name "
read file
error_fn()
{
echo "ERROR: $1"
echo "ERROR: $2"
exit 10
}
until [ $# = $file ]
do
echo you entered $file
error_fn "The File Was Not found, Please try Again"
done
exit 10
if [ $1 -eu ]
then echo The File is there and you own it
else
echo The file was found, but you do not own it
fi
exit 10