这个问题在这里已有答案:
-
[String comparison in bash. [: not found 6个答案
我有一个shell脚本,我想检查它是否's being run by root. If it' s然后我设置变量 SUDO='sudo'
前置到后续命令 . 这样,用户从shell获得一个很好的权限被拒绝错误消息,如果他们正在运行sudo,它正确地开展业务 . 但是,对于以下代码,我得到:
myscript.sh: [: -ne: unexpected operator
代码是:
#!/bin/sh
SUDO=""
if [ $EUID -ne 0 ]; then
SUDO='sudo'
fi
我正在运行它: sh myscript.sh
as this is not a bash script . 这不是sh vs bash afaik的问题 . shebang说 /bin/sh
,我用 sh
运行它 .