Why does the following script display an unexpected operator message and fail when run with SH, but not with BASH.!/bin/shif [ $UID -ne 0 ]then        echo You must be root.        exit 1else        echo Open sesame.        exit 0fi
Why does sh display an error when bash does not?
shell script
Not all shells define a variable UID. This is a bash and zsh feature only. In other shells, the UID variable is not defined, so your test command expands to [ -ne 0 ] which is a syntax error.A portable way to obtain the user ID is with the id utility.if [ $(id -u) -ne 0 ]; then 