Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check existence of any file in csh script?

Tags:

linux

csh

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?

like image 869
dcds Avatar asked Jan 07 '15 07:01

dcds


People also ask

How do you check if any file exists in a directory in shell script?

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!"

How do I check if a file exists in Linux?

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).


1 Answers

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).

like image 77
Martin Tournoij Avatar answered Oct 17 '22 01:10

Martin Tournoij