How to get the fully qualified name (FQN) on Unix in a bash script?

view full story

http://serverfault.com – I have tested hostname on several servers (RedHat, Ubuntu), and hostname -f has proven unreliable, returning sometime the short name only (as described in this question). I can see the fqn in the aliases: hostname -a (one of the aliases is the fqn I look for), but the order of the aliases is not fixed. Is there another way to get the fully qualified name reliably, and store it in a bash variable? (HowTos)