...

shell脚本报错:"[: =: unary operator expected"

发布于 分类 Linux

Markdown版本

报错DEMO:

[root@localhost ~]# cat test.sh
#!/bin/bash
if [ $1 = 'noco' ] ; then
    echo 'yes'
else
    echo 'no'
fi
[root@localhost ~]# ./test.sh
./test.sh: line 3: [: =: unary operator expected
no 

解决办法:

#方法1
#!/bin/bash
if ["$1" = 'noco' ] ; then
    echo 'yes'
else
    echo 'no'
fi

#方法2
#!/bin/bash
if [[ $1 = 'noco' ]] ; then
    echo 'yes'
else
    echo 'no'
fi

本文标题: shell脚本报错:"[: =: unary operator expected"

本文地址: https://seonoco.com/blog/shell-script-error-unary-operator-expected

本文是否有所帮助?
00
0

评论

网友