You are not logged in.
Pages: 1
Hello,
If the hostname command is not installed, what would be the best way (understand: usable with a basic installation) to have an alternative to the hostname --fqdn command to get the fully qualifed domain name of localhost?
The hostnamectl command does not provide fqdn and systemd-resolved may not be available if we do not use systemd to configure the network…
Offline
"hostname --fqdn" effectively just prints the first domain from "getent hosts" - it doesn't even have to be a fqdn.
How you get that (getent is part of glibc) depends on what you consider a "basic installation", but bash parameter expansion can do that.
Maybe you explain what you actually want to achieve here?
Online
I ask this question because I encountered a bug in the use of liquiprompt that attempts to retrieve the host name via the hostname command.
The maintainer handled the initial issue by fetching the values from the environment variables provided by zsh or bash, but the issue still arises for one of the features of this prompt that displays fqdn as hostname.(https://github.com/nojhan/liquidprompt/ … 2278-L2286)
That's why I'm trying to find a solution that can be used regardless of the network configuration and without the hostname command, to find the FQDN of the host
Offline
getent hosts | awk 'NR==1{print $2}'
getent hosts | awk '{print $2;exit}'
awk is a dependency of pacman, so that's basic enough, I guess?
Online
something like this should do the trick:
getent hosts | awk /"${HOSTNAME:-${HOST-}}"./'{print $2}'
thanks for the answers
Offline
As mentioned, hostname doesn't actually care about /etc/hostname - no idea how relevant that is w/ liquiprompt.
Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.
Online
Pages: 1