0

私は次の機能を持っています:

testit()
{
[ "$1" == "OK" ] && echo "good" || echo "bad"
}

しかし、期待どおりには機能しません。私はそれを次のように呼ぶことができます:

testit 'OK' #good
testit 'abc' #bad

しかし、私がそれを呼び出すとき:

testit '('

「sh:パレンを閉じる必要があります」で失敗します。テストする文字列を引用しましたが、なぜ引用符がないように動作するのですか?

4

2 に答える 2

1

これは、シェル実装のバグである可能性があります。最新のCentOSでコードをテストしましたが、正常に動作します。

testit '('
bad

 sh -version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
于 2012-07-10T12:25:19.127 に答える
0

これが醜い回避策です:

if [ "x$1" = "xOK" ]; ...
于 2012-07-10T14:51:00.903 に答える