【发布时间】:2018-08-28 14:37:49
【问题描述】:
这是我的脚本,我想在文件中查找模式。如果找到模式,我知道grep -q '<Pattern>' '<file>' && echo $? 的退出状态为 0。但我收到 if: Expression Syntax 错误。
if ( (grep -q '<Pattern>' '<file>' && echo $?)==0 ) then
echo "Pattern found"
else
echo "Pattern not found"
endif
【问题讨论】:
-
我不知道 tcsh,但是在 bash 和 POSIX sh 中,你只需要
if grep -q '<pattern>' '<file>'; then。 -
我也会在
tcsh中这样做:sh -c 'if grep -q "<Pattern>" "<file>"; then ... ':)
标签: linux shell scripting tcsh