shell if 如何取非

lewis 2019-01-23 26次阅读

在Shell脚本中,可以使用!操作符来取非。具体语法如下:

if ! condition; then
# code to be executed if the condition is false
else
# code to be executed if the condition is true
fi

在上述代码中,!操作符用于对condition进行取非操作。如果condition为true,则执行else后面的代码块;如果condition为false,则执行if后面的代码块。



发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。