how to check existence of any file in csh script?

dcds picture dcds · Jan 7, 2015 · Viewed 50.8k times · Source

For checking the existence of any file in csh script I am using

if [ -f /var/opt/temip/conf/.temip_config ]

but I am getting below error

if [ -f /var/opt/temip/conf/.temip_config ]

if: Expression Syntax.

Can anyone tell me how to do this?

Answer

Martin Tournoij picture Martin Tournoij · Jan 7, 2015

From the manpage:

f
    Plain file

You use it with a if statement:

if ( -f file.txt ) then
    echo Exists
else
    echo No such file
endif

Based on this question and your previous question, you seem to be rather clueless as to how csh syntax works, since you keep using POSIX shell syntax. I would strongly suggest that you either familiarise yourself with the csh syntax, or just use a POSIX shell (which is probably better for scripting anyway).