在 shell 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 : integer expression expected
最佳答案
要进行字符串比较,您需要使用类似以下内容的内容:
[ "$1" == "offs0.5" ]
请注意,在比较字符串时,使用 eq
的表达式正在寻找算术比较。
而且,在你的表情中,你有
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"
关于linux - 如何在Linux中搜索单词中的某些字母?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19403238/