以下に、サンプル test-string.sh を示します。 #!/bin/bash foo=aaa var=aaa if [ ${foo} = ${var} ]; then echo "equal" fi if [ ${foo} != "bbb" ]; then echo "not equal" fi if [ -n ${foo} ]; then # 変数fooのサイズが1以上であれば真 echo "not null" fi foo= if [ -z ${foo} ]; then # 変数fooのサイズが0であれば真 echo "null" fi これを実行すると、以下の結果になります。 $ ./test-string.sh equal not equal not null null 文字が含まれていることを判定 文字列の中に、特定の文字が含まれているかどうか判定する方法を紹介します。