if文中にシェルスクリプトがクラッシュしていますか? [閉鎖]

if文中にシェルスクリプトがクラッシュしていますか? [閉鎖]
for hi in `seq 0 100`
do
    new_val=1
    if `expr $hi % 5` -eq 5
    then
        echo hello
    elif `expr $hi % 5` -eq 6
    then
        echo bye
    elif `expr $hi % 5` -eq 7
    then
        echo whats up
    fi
    echo $new_val
done

なぜ衝突するのですか?目標は、循環番号モジュールで5が5、6、または7であることを確認することです。

ベストアンサー1

変更されたスクリプトは次のようになります。

#!/bin/sh 

for hi in $(seq 0 100)
do
    if [ "$(expr $hi % 5)" -eq 5 ]
    then
        echo hello
    elif [ "$(expr $hi % 5)" -eq 6 ]
    then
        echo bye
    elif [ "$(expr $hi % 5)" -eq 7 ]
    then
        echo whats up
    fi
    echo "$hi"
done

しかし、モジュロ5演算の残りは決して5、6、または7ではないため、ループはifを入力しません。

おすすめ記事