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?
In order to check if a file exists in Bash using shorter forms, specify the “-f” option in brackets and append the command that you want to run if it succeeds. [[ -f <file> ]] && echo "This file exists!" [ -f <file> ] && echo "This file exists!" [[ -f /etc/passwd ]] && echo "This file exists!"
When checking if a file exists, the most commonly used FILE operators are -e and -f . The first one will check whether a file exists regardless of the type, while the second one will return true only if the FILE is a regular file (not a directory or a device).
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With