【问题标题】:error in constructing if statement in csh在 csh 中构造 if 语句时出错
【发布时间】:2019-08-31 04:55:08
【问题描述】:

我试图在 c-shell 中执行这个 if 语句,但是语法有问题导致它不起作用

if(grep "hello" $HOME/file) then 
echo "I am here" 
endif


if(grep "hello" $HOME/file) then echo "I am here" end if
if: Expression Syntax.

【问题讨论】:

  • endif 之间有一个空格;也许这就是问题所在?

标签: csh


【解决方案1】:

在 'csh' 中,'if' 语句只会采用 'expression'。假设您的脚本要检查“grep”命令的状态,请考虑在执行“grep”后立即检查“$status”。

grep "hello" $HOME/file
if ( $status === 0 ) then
    echo "I'm here"
end if

#Single line 'if'
grep "hello" $HOME/file
if ( $status === 0 ) echo "I'm here"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-10
    • 2017-07-08
    相关资源
    最近更新 更多