shell脚本报错:"[: =: unary operator expected"
发布于 分类 Linux
56天前 有1个用户阅读过
报错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
-- The End --