I occasionally put together shell scripts to automate tasks, which would otherwise need me to remember very long commands (e.g. converting digital camera movie clips into DivXs for our Web site). I'm not really a programmer, but can usually find enough advice via Google to get by.
One small script I'm trying to get working, assigns a disk image file (which I use for running FreeDOS under Bochs) to the loopback device and then mounts it, so I can copy files to and from the image.
Because the "mount" command is involved, I want the script to check whether the user is logged in as superuser, and at the very least, exit if not. I found this routine and tried it as a non-superuser:
if [ $UID -ne $ROOT_UID ]
echo "Must be root to run this script."
It gave me this message:
[: 500: unary operator expected
...and didn't exit, so the other two operations (loopback, and mount) failed as I was not the superuser.
Does anyone know what might be wrong with the above code? Alternatively, how could the script be modified so that "sudo" would be called if the user was not root? (I would be the only user who could execute it.)