I am attempting to write a script that automates the installation of ports/packages on new FreeBSD installs. To do this, the user who executes the script must be root.
The system is "supposed" to be virgin meaning bash
and sudo
may or may not be installed; so I am trying to account for it. To do this, I am checking if the user ID equals 0.
The problem is, between bash and sh, the environment variables are different:
- bash -> $EUID (all caps)
- sh -> $euid (all lower)
Is there a different way other than the environment variable to check for root user or should I just adjust the checking of the user based on environment?
sh
on FreeBSD is the Almquist shell, not the Bourne shell. And theeuid
shell variable that you describe is set by neither the Almquist shell nor the Bourne shell. It is set by the TENEX C shell. You will find it quite difficult to write a script that works on both the Almquist/Bourne Again/Korn/Z shells and the C shell. – JdeBP Mar 05 '18 at 15:07sh
. But by the presence of that variable you are clearly not. The Almquist shell, as I said, does not set such a variable.root
does not have the Almquist shell as its login shell, note. – JdeBP Mar 05 '18 at 15:38sh
on FreeBSD is the Almquist shell and root does not have the Almquist shell as its login. These statements are contradictory. Either root has the Almquist shell in FreeBSD and I'm running it or FreeBSD doesn't use the Almquist shell. I am running FreeBSD and logged in as root using the *default* sh shell. – Allan Mar 05 '18 at 15:55root
has the TENEX C shell as its login shell, and that does not contradictsh
being the Almquist shell at all. As I said, you think that you are runningsh
. But in fact that is not what you are doing, as the presence of a shell variable set by the TENEX C shell,root
's login shell, clearly tells us. – JdeBP Mar 06 '18 at 06:47