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.
edit:
I do have to use an alias, it is a file name that you give (a static file) and even when I change outelse if
for elif
I still receive the syntax error I described in the question.
EDIT2:
I found the problem, I removed the fi;
before the elif statement but now i receive a missing ']'
error.
else
? – Timothy Martin Oct 12 '17 at 23:55else if
, but the correct syntax iselif
. – nxnev Oct 13 '17 at 0:02