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?
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?
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).
In CShell for checking of the existence of a file use -e
option
The name of the file does not have to be "hard coded" into the if statement, but may be a parameter like this:
if (-e "$filePath") then
Here is a full list of the Cshell file queries.
-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
© 2022 - 2024 — McMap. All rights reserved.
sh
which is probably what you should be using anyway. Without the context of the rest of your script, we can't really tell whether changing the first line to#!/bin/sh
would be feasible, though. – Yarkandcsh
. Code your script in POSIX sh (for portability), or in GNUbash
or in Python or inzsh
– Aftersensation