Reputation: 577
This is working fine on bash but I need to get it working in tcsh. Below is the code I use:
if [ -e ~/test/file ]; then echo 'yes'; else echo | mail -s 'not done' [email protected] ; fi
This basic code gives me an error saying if: Expression Syntax
.
I have no idea what the error means and not sure why the if statement is not working. I have spaces before/after brackets. I tried if ( test -f ~/test/file )
and got the same error.
I am lost as by default I use bash and this error gives no insight. I see a few similar cases but nothing about checking existence of a file.
Upvotes: 0
Views: 1550
Reputation: 440
you can run on one line using the test command in a sequence of commands:
test -e ~/test/file && echo 'yes' || mail -s 'not done' [email protected]
or if you are not interested in the positive case, you can use the short "if" format
if ( ! -e ~/test/file ) mail -s 'not done' [email protected]
Upvotes: 1
Reputation: 354
See the 'File inquiry operators' section of the tcsh man page.
The tcsh sytnax for what you are describing is
if ( -e ~/test/file ) then
echo 'yes'
else
echo | mail -s 'not done' [email protected]
endif
Note that tcsh isn't good at running pieces of code on one line.
Upvotes: 1