shell脚本语言中“与、或、非的使用“

时间:2025-02-28 08:25:12
前言

在部署程序或者执行定时任务等需求时,会使用到逻辑判断的shell脚本语言

逻辑使用
  • 形式:
    条件1 与 条件2

  • 使用方法一

if [ $value == "stop" -a $value == "restart" ]; then
  excute=$value
fi  
  • 使用方法二
if [ $value == "stop" ] && [ $value == "restart" ]; then
  excute=$value
fi  
  • 形式:
    条件1 或 条件2

  • 使用方法一

if [ $value == "stop" -o $value == "restart" ]; then
  excute=$value
fi  
  • 使用方法二
if [ $value == "stop" ] || [ $value == "restart" ]; then
  excute=$value
fi  
结语

… …