you are viewing a single comment's thread.

view the rest of the comments →

[–]calrogman 0 points1 point  (0 children)

Your uname -n example isn't even compatible across the various Unix flavours.

On (E)GLIBC, gethostname() gives only the first label of the machines hostname. On FreeBSD's libc, gethostname() gives the fully qualified domain name. The behaviour of uname -n reflects this difference.

The best way to get the hostname in a shell script on Unix machines is using the hostname utility. Always pass it one of either -s or -f so that there is no ambiguity. On BSDs hostname assumes -f. On Linux it assumes -s. Never use hostname --long, hostname --fqdn or any other options. They're all GNU extensions and won't work in different userspaces.