0

渡された最初のパラメーターを評価する or 演算子を含む if ステートメントをどのように作成しますか?

運が悪いので、下部のリンクから直接例をコピーしました。また、オンラインで見つけた他の例をコピーして失敗しました。

# not working
if [ "$1" = "restart" || "$1" = "reload"]; then
      echo "you passed in $1"
      exit 3 
fi

# not working
if [[ "$1" = "restart" || "$1" = "reload"]]; then
      echo "you passed in $1"
      exit 3 

# not working
if [ $1 = "restart" || $1 = "reload"]; then
      echo "you passed in $1"
      exit 3
fi

# not working
if [ $1 == "restart" || $1 == "reload"]; then
      echo "you passed in $1"
      exit 3
fi

# not working
if [ $1 == "restart" || $1 == "reload"]; then
      echo "you passed in $1"
      exit 3
fi

# not working
if [ "$1" = "restart" || "$1" = "reload" ]; then
      echo "you passed in $1"
      exit 3 
fi

# not working
if [ "$1" == "restart"]  || [ "$1" == "reload" ]; then
      echo "you passed in $1"
      exit 3 
fi

さらに、私が見つけることができる他のすべての構文....

次のエラーのいずれかが表示されます

/etc/init.d/gitlab: 192: [: =: unexpected operator

また

/etc/init.d/gitlab: 192: [: missing ]

また

/etc/init.d/gitlab: 194: [: missing ]
/etc/init.d/gitlab: 194: [: ==: unexpected operator

リソース:
http://tldp.org/LDP/abs/html/comparison-ops.html

https://unix.stackexchange.com/questions/47584/in-a-bash-script-using-the-conditional-or-in-an-if-statement

シェル スクリプトで論理 OR 演算を実行する方法

http://www.thegeekstuff.com/2010/06/bash-if-statement-examples/

4

2 に答える 2