1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

メモ:/bin/shで使えないオペレーターがあるんですね

Posted at

シェルスクリプト実行時にこんなエラーが。

sh -c "if [ a == b ]; then echo hello ; fi"
sh: 1: [: a: unexpected operator

エラーメッセージを見ると[が使えないのかな?とかおもったけど違って、
==が使えないのが原因だった。

変なところでハマった。

sh -c "if [ a != b ]; then echo hello ; fi"
hello

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
ここに色々書いてあるが、POSIX準拠のShellのtestコマンドの文字列比較オペレーターは ==ではなく=でした。

Bash使えば?って話でもあるが。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?