For my homework I need to write an alias that checks if a given file is regular and readable. The problem i am getting is that if i include else if or elif i get this error...
-bash: syntax error near unexpected token `else'
here is my code...
alias getname='read filename' alias vfile='getname; if [ ! -f $filename ]; then echo "Irregular file"; (exit 1); elif [ ! -r $filename]; then echo "Not readable"; (exit 2); fi;'
I need to use an else if so that if there is an error only one statement will be printed.
I am aware that a shell function or script would be more practical but for the assignment I have to use an alias. I am still very new to UNIX so any help will be very much appreciated.
I do have to use an alias, it is a file name that you give (a static file) and even when I change out
else if for
elif I still receive the syntax error I described in the question.
I found the problem, I removed the
fi; before the elif statement but now i receive a