Difference between EUID and UID? Difference between EUID and UID? shell shell

Difference between EUID and UID?


They're different when a program is running set-uid. Effective UID is the user you changed to, UID is the original user.


It only works on bash, not in dash (in Debian based distros as Ubuntu sh is usually a symlink to dash).

If you are running the script interactively you might not have bash configured as your default shell, run bash before trying.

If you are running it from console:

bash script.sh

If you are running it using its path (for example ./script.sh) ensure the first line of the script is:

#!/bin/bash

And not:

#!/bin/sh

For a more generic way to do it check: https://askubuntu.com/questions/15853/how-can-a-script-check-if-its-being-run-as-root

In that post the command id is mentioned, where:

id -u    # is the EUIDid -u -r # is the UID