3

7 行目 (if ステートメント) でエラーが発生する理由を教えてください。

test.sh: line 7: [: command_exists: unary operator expected

ありがとう!

#!/usr/bin/env bash

command_exists () {
  command -v "$1" &> /dev/null ;
}

if [ ! command_exists ruby ]; then  # test.sh: line 7: [: command_exists: unary operator expected
  echo 'found ruby'
else
  echo 'ruby not found'
fi
4

1 に答える 1

5
if ! command_exists ruby; then

Bashでif、コマンドを実行し、その戻り値に基づいて動作します。[たまたまコマンドです。

于 2012-05-22T00:33:53.840 に答える