sh(bashではない)は単一の[または二重[[角かっこ?

sh(bashではない)は単一の[または二重[[角かっこ?

このスクリプトがあります。

#!/usr/bin/env sh

# note: we must use sh instead of bash, it's more cross-platform

set -e;

if [[ "$skip_postinstall" == "yes" ]]; then   # TODO rename 'skip_postinstall' to something more specific
    echo "skipping postinstall routine.";
    exit 0;
fi

export FORCE_COLOR=1;
export skip_postinstall="yes";   # TODO rename 'skip_postinstall' to something more specific

mkdir -p "$HOME/.oresoftware/bin" || {
  echo "Could not create .oresoftware dir in user home.";
  exit 1;
}

(
  echo 'Installing run-tsc-if on your system.';
  curl  -H 'Cache-Control: no-cache' -s -S -o- 'https://raw.githubusercontent.com/oresoftware/run-tsc-if/master/install.sh' | bash || {
     echo 'Could not install run-tsc-if on your system. That is a problem.';
     exit 1;
  }
) 2> /dev/null


if [[ "$(uname -s)" != "Darwin" ]]; then
   exit 0;
fi

if [[ ! -f "$HOME/.oresoftware/bin/realpath" ]]; then
  (
    curl --silent -o- 'https://raw.githubusercontent.com/oresoftware/realpath/master/assets/install.sh' | bash || {
       echo "Could not install realpath on your system.";
       exit 1;
    }
  )
fi

# the end of the postinstall script

私がそれを実行すると、私は得ます:

./assets/postinstall.sh: 7: ./assets/postinstall.sh: [[: not found
Installing run-tsc-if on your system.

 => Installing 'run-tsc-if' on your system.
 => run-tsc-if download/installation succeeded.

./assets/postinstall.sh: 29: ./assets/postinstall.sh: [[: not found
./assets/postinstall.sh: 33: ./assets/postinstall.sh: [[: not found

ただし、ダブル[[角かっこを単一の角かっこに置き換えると、次のような結果が得られます。

./postinstall.sh: 7: [: unexpected operator

これはただ次のものです:

if [ "$skip_postinstall" == "yes" ]; then  
    echo "skipping postinstall routine.";
    exit 0;
fi

ではどうすればいいですか?代わりにandを使ってみましたが、testそれも機能しませんでした。[[[

ベストアンサー1

[[kshから派生した「拡張テスト」で、bash / zshでもサポートされているためしてはいけないそれらを認識しなさい。また、この==演算子はPOSIXではなく、=文字列比較のためのシェルテスト演算子です。

これら2つは非常に一般的なものです。バシズム

おすすめ記事