I've got this C code getenv("HOSTNAME");, which returns NULL on a VM running Linux (Guixsd). While investigating I ran the following three commands, which work as expected:
hostname => guixos
echo $HOSTNAME => guixos
cat /etc/hostname => guixos (no newline)
So I expected hostname to also be printed out by env, but...
env | fgrep HOST =>
So, I've got three methods of accessing the hostname which actually work, and two which I expect to work, but don't. Can someone explain why those two methods don't also give me the hostname?
HOSTNAME is a variable that bash (but not other shells) sets by default. It is not exported.
Since it's not exported, it will not be inherited by env or any C program invoked from a bash shell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With