【发布时间】:2012-05-20 03:07:14
【问题描述】:
我希望在cat /etc/passwd | grep "sysa" 不正确时执行echo 命令。
我做错了什么?
if ! [ $(cat /etc/passwd | grep "sysa") ]; then
echo "ERROR - The user sysa could not be looked up"
exit 2
fi
【问题讨论】:
-
!不应该在括号内吗?即[ ! EXPR ] -
@acraig5075 无论哪种方式都有效,但在此语句中根本不需要测试命令(括号内的内容)。
标签: bash if-statement syntax boolean-expression