脚本中 if 判断细节

if [[ $1 == "fedora" ]];then
      echo "redhat"
elif [[ $1 == "redhat" ]];then
       echo "fedora"
else
      echo '/root/foo.sh redhat | fedora'
      exit 1
fi

脚本中 if 判断细节

case $1 in
        redhat)
                echo fedora
                ;;
        fedora)
                echo redhat
                ;;
        *)
                echo '/root/foo.sh redhat | fedora'
                ;;
esac

脚本中 if 判断细节

-eq 是做数值比较, == 是做字符串比较

if [ ] 是 POSIX 兼容版写法
if [[ ]] 是 bash zsh 支持的升级版

[ -L "$file" ] && [ -f "$file" ]
[[ -L $file && -f $file ]]

工作中 if 判断用 [[ ]] 和 == 来做是没问题的,相关细节如上

相关文章:

  • 2022-12-23
  • 2021-12-04
  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
  • 2021-08-03
  • 2021-09-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2022-01-05
  • 2022-12-23
  • 2021-10-02
相关资源
相似解决方案