2015-01-07 801 views
5

用于检查CSH脚本中的任何文件的存在,我使用如何检查csh脚本中是否存在任何文件?

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

,但我得到以下错误

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

if: Expression Syntax. 

谁能告诉我如何做到这一点?

+0

这根本不是有效的Csh语法。 这是一件好事,因为你可能不应该在Csh中做你的脚本。 您的语法适用于'sh',这可能是您应该使用的任何东西。如果没有脚本其余部分的内容,我们无法确定是否将第一行改为'#!/ bin/sh'是可行的。 – tripleee

+0

@tripleee你能告诉我如何在csh脚本中检查文件的存在吗? – dcds

+2

不,我不使用Csh,也不想学习它,也不应该。规范的引用是http://www.perl.com/doc/FMTEYEWTK/versus/csh.whynot,但您可以在Google中找到更多。 – tripleee

回答

4

the manpage

f 
    Plain file 

你有if语句中使用它:

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

基于这个问题and your previous question,你似乎是相当无能,如何csh语法的作品,因为你继续使用POSIX shell语法。我会强烈建议你要么熟悉csh语法,要么只是使用POSIX shell(这对于脚本来说可能更好)。

+0

最后一行应该是“endif”,而不是“end”。 –

+0

是在csh上使用posix。 – kdubs

3

在CShell一个文件的存在检查使用-e选项

文件的名称并没有被“硬编码”到if语句,但 可能是这样一个参数:

if (-e "$filePath") then 

以下是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 
相关问题