-1

シェルrun.shで私は持っています

find . -name "*.txt" -exec grep -H SNR {} \; | grep "$1" > result.txt
if[ "$1" -eq "offs0.5"] 
 then 
 fi

私が入力した場合:run.sh offs0.5

このエラー:

[: offs0.5 : 整数式が必要です

4

1 に答える 1

0

文字列比較を行うには、次のようなものを使用する必要があります。

[ "$1" == "offs0.5" ] 

eq文字列を比較している間、式 with は算術比較を探していることに注意してください。

また、あなたの表現には

if[ "$1" -eq "offs0.5"] 
          ^^^        ^ needed space
          no eq on string comparison

テスト

$ d="offs0.5"
$ 
$ [ "$d" == "offs0.5" ] && echo "yes"
yes

$ d="offs0.5aa"
$ [ "$d" == "offs0.5" ] && echo "yes"
于 2013-10-16T12:22:17.903 に答える