Skip to content

Instantly share code, notes, and snippets.

@blueberrystream
Created September 10, 2012 06:34
Show Gist options
  • Save blueberrystream/3689251 to your computer and use it in GitHub Desktop.
Save blueberrystream/3689251 to your computer and use it in GitHub Desktop.
#!/bin/bash
hoge="#"
if [ $hoge!="#" ]; then
echo "hoge is not # (1st)"
fi
if [ "$hoge " != "# " ]; then
echo "hoge is not # (2nd)"
fi
# ダブルクォートで囲むだけでいいんじゃねーのって話
if [ "$hoge" != "#" ]; then
echo "hoge is not # (3rd)"
fi
@blueberrystream
Copy link
Author

GNU bash, version 3.00.16(1)-release (i386-pc-solaris2.10) だと true って表示される。

@blueberrystream
Copy link
Author

さっきのコメなし。
GNU bash, version 3.00.16(1)-release (i386-pc-solaris2.10) だと
hoge is not # (1st)
とだけ表示される。

@blueberrystream
Copy link
Author

GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu)でも同じ結果らしい。どうにもbashが != の比較なのに文字列としての比較じゃないことをしてるらしいとかなんとか。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment