「ShellScript」testコマンドで文字列を比較するサンプル

2021年3月5日

書式
test 文字列1 = 文字列2
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
cftA="arkgHame"
cftB="arkgame"
if test $cftA = $cftB
then
echo '2つの文字列が等しい!'
else
echo '2つの文字れが等しくない'
fi
cftA="arkgHame" cftB="arkgame" if test $cftA = $cftB then echo '2つの文字列が等しい!' else echo '2つの文字れが等しくない' fi
cftA="arkgHame"
cftB="arkgame"
if test $cftA = $cftB
then
    echo '2つの文字列が等しい!'
else
    echo '2つの文字れが等しくない'
fi

実行結果
# sh test01.sh
2つの文字れが等しくない

shellscript

Posted by arkgame