How to check for any file in csh script?

To check the existence of any file in csh script I use

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

but i'm getting below the error

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

Can someone tell me how to do this?

+5
source share
2 answers

From manpage :

 f Plain file 

You use it with an if :

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

Based on this question and your previous question , you do not seem to know how the csh syntax works, as you continue to use the POSIX shell syntax. I would strongly suggest that you either familiarize yourself with the csh syntax, or simply use the POSIX shell (which is probably better for scripting).

+4
source

In CShell, to check for the existence of a file, use the -e option

The file name does not have to be โ€œhard-codedโ€ in the if statement, but it can be such a parameter:

  if (-e "$filePath") then 

Here is the complete list of requests for Cshell files.

 -e file file merely exists (may be protected from user) -r file file exists and is readable by user -w file file is writable by user -x file file is executable by user -o file file is owned by user -z file file has size 0 -f file file is an ordinary file -d file file is a directory 
+4
source

Source: https://habr.com/ru/post/1210528/


All Articles