字符串比较中的算术语法错误

chh*_*rma 4 shell shell-script test

我写了一个 shell 脚本,它以文件名作为参数,例如 user/test.txt。如果用户不希望提供他/她可以提供的文件名“无”,我想将此文件参数设为可选

在脚本内部,我只是检查文件名参数是否包含“无”

if [ $filename -eq "NONE" ];then
cmd;
fi
Run Code Online (Sandbox Code Playgroud)

当“无”作为参数脚本传递时工作正常,但是当传递 user/test.txt 时,我收到以下错误消息,我不想在控制台上打印

arithmetic syntax error
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?

ctr*_*lor 8

[ bla bla bla ]相当于test bla bla bla

man test

   STRING1 = STRING2
          the strings are equal

   STRING1 != STRING2
          the strings are not equal

   INTEGER1 -eq INTEGER2
          INTEGER1 is equal to INTEGER2
Run Code Online (Sandbox Code Playgroud)

因此,你需要=-eq