if 'hostname' is called with unrecognised cli flags/options it produces an error message plus it's 'usage' information and terminates with success (0). When called with unrecognised flags/options, it should terminate with an error code. Especially so since it produces the error message. (Agreed, it successfully produces the 'usage' information, but that is probably as expected and only marginally helpful for a bash script calling 'hostname'.) Example: # hostname --version net-tools 1.60_p20161110235919 # hostname --xyz; echo ${?}; hostname: unrecognized option '--xyz' <======== Note! Error message! Usage: hostname [-v] {hostname|-F file} set hostname (from file) domainname [-v] {nisdomain|-F file} set NIS domainname (from file) hostname [-v] [-d|-f|-s|-a|-i|-y|-n] display formatted name hostname [-v] display hostname hostname -V|--version|-h|--help print info and exit dnsdomainname=hostname -d, {yp,nis,}domainname=hostname -y -s, --short short host name -a, --alias alias names -i, --ip-address addresses for the hostname -f, --fqdn, --long long host name (FQDN) -d, --domain DNS domain name -y, --yp, --nis NIS/YP domainname -F, --file read hostname or NIS domainname from given file This command can read or set the hostname or the NIS domainname. You can also read the DNS domain or the FQDN (fully qualified domain name). Unless you are using bind or NIS for host lookups you can change the FQDN (Fully Qualified Domain Name) and the DNS domain name (which is part of the FQDN) in the /etc/hosts file. 0 # <========== Note return code '0', # which "by convention" is interpreted as success. I fully recognise that 'man hostname' doesn't document any return codes at all, but there is this nagging feeling that a program should return '0' on success and something else (in worst case just '1') on failure.
this was broken in 2012 here: https://sourceforge.net/p/net-tools/code/ci/699e5db88236deff1ff4cc657a8d978c25790587 i've fixed it upstream here: https://sourceforge.net/p/net-tools/code/ci/aebd88ef8d6e15f673b62a649a50d07ed727c888 so it'll make it into the next snapshot at some point.