I'm writing a bash script where I want to exit if the user is not root. The conditional works fine, but the script does not exit.
[[ `id -u` == 0 ]] || (echo "Must be root to run script"; exit)
I've tried using &&
instead of ;
but neither work.
exit 1
in order to make understand the parent process that a problem occured. – SamK Nov 04 '11 at 16:32[[
for numeric comparison, use((
. – Chris Down Nov 04 '11 at 19:59[[
is fine, as long as you use-eq
instead of==
. – Šimon Tóth Nov 24 '11 at 10:10ksh
deprecated it (and will output a warning). – Chris Down Nov 24 '11 at 11:13(( EUID )) && ...
– Chris Down Nov 24 '11 at 11:14