如何检查csh脚本中是否存在任何文件?

dcd*_*cds 8 linux csh

用于检查我正在使用的csh脚本中是否存在任何文件

if [ -f /var/opt/temip/conf/.temip_config ]
Run Code Online (Sandbox Code Playgroud)

但我得到低于错误

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

if: Expression Syntax.
Run Code Online (Sandbox Code Playgroud)

谁能告诉我怎么做?

Mar*_*oij 8

联机帮助页:

f
    Plain file
Run Code Online (Sandbox Code Playgroud)

您将它与if声明一起使用:

if ( -f file.txt ) then
    echo Exists
else
    echo No such file
endif
Run Code Online (Sandbox Code Playgroud)

基于这个问题和您之前的问题,您似乎对csh语法如何工作毫无头绪,因为您继续使用POSIX shell语法.我强烈建议你要么熟悉csh语法,要么只使用POSIX shell(这对于脚本来说可能更好).


kvi*_*vek 5

在CShell中检查文件使用-e选项是否存在

文件名不一定要“硬编码”到if语句中,而可以是这样的参数:

 if (-e "$filePath") then
Run Code Online (Sandbox Code Playgroud)

这是Cshell文件查询的完整列表。

-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
Run Code Online (Sandbox Code Playgroud)