小编Lam*_*aEu的帖子

不区分大小写地比较字符串

我想比较Hello Worldhello world.结果应该是真的,好像它们是平等的.我正在做:

while read line; do

    newLine="$newLine$line"
done < $1

newp="Hello World"
if (( ${newp,,}==${newLine,,} )); then
    echo "true"
else
    echo "false"

fi
Run Code Online (Sandbox Code Playgroud)

当我传递包含以下内容的文本文件时:

#filename: file.txt

hello world
Run Code Online (Sandbox Code Playgroud)

输出似乎是:

./testScript.txt: line 20: 0à»: hello world==hello world : syntax error in expression (error token is "world==hello world ")
+ echo false
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?此外,有点无关,有没有办法将行中的行传递file.txt给字符串(newLine)而不做while我已经做过的事情?

unix bash shell

1
推荐指数
1
解决办法
50
查看次数

标签 统计

bash ×1

shell ×1

unix ×1