我想比较Hello World
到hello world
。结果应该是真实的,就好像它们是平等的。我做:比较字符串不区分大小写
while read line; do
newLine="$newLine$line"
done < $1
newp="Hello World"
if ((${newp,,}==${newLine,,})); then
echo "true"
else
echo "false"
fi
当我通过包括一个文本文件:
#filename: file.txt
hello world
输出似乎是:
./testScript.txt: line 20: 0à»: hello world==hello world : syntax error in expression (error token is "world==hello world ")
+ echo false
我在做什么错在这里?此外,有点无关,有没有办法将file.txt
中的行传递给一个字符串(newLine),而没有这样做while
我已经完成了?
'((a == b))'是数学和数字。 '[[“$ a”=“$ b”]]'用于字符串。空格不是可选的。 –
即使你得到了你的具体问题的答案,周围的循环意味着任何测试都会说'x \ y'匹配'xy'并且可以有其他错误的[错误]匹配。请参阅[为什么要使用shell循环处理文本被认为是坏习惯](http://unix.stackexchange.com/questions/169716/why-is-using-a-shell -loop到过程文本视为坏实践)。 –
您可以使用带'hello world'风格的'grep -v'来测试其他风格。 – boardrider