我有以下内容
if [[ curl https://www.example.com | grep -q "Match 1 Found" = 0 ]]
then
echo "Match 1 Found"
elif [[ curl https://www.example.com | grep -q "Match 2 Found" = 0 ]]
then
echo "Match 2 Found"
else
echo "No Match Found"
PS:我等于零,因为如果为 True,shell 返回 0
[[ ]]
用于评估条件表达式,但在测试命令时不需要它。命令的退出状态直接通过if
测试。
所以只需写:
if curl https://www.example.com | grep -q "Match 1 Found"