I'm creating a login message for my computer inside of /etc/bashrc and would like to greet them to the computer with the computer's name showing.
Here's my code:
# (system stuff here) echo "Welcome, $(whoami)." When I use login on any user, it gives me what I'd expect: Welcome, avgjoe for example.
However, I'd like to make it output Welcome, avgjoe, to Tower of Nix - my computer's name has been set (through System Preferences) to "Tower of Nix" already.
So, without hard-coding it in there (i.e. echo "Welcome, $(whoami), to Tower of Nix."), how can I get the name of my computer?
I've already tried hostname, but that outputs 192.168.2.13.
Turns out, scutil --get ComputerName does exactly what I want (outputs Tower of Nix), but when I looked at the man page for scutil, it stated:
HISTORY
The
scutilcommand appeared in the Mac OS X Public Beta.
So it probably won't work on all operating systems such as Linux, *BSD, etc.
My question: How can I get the name of the computer on any (or nearly any) derivative of UNIX?
hostnamesounds more likehostname -ito me. For completeness' sake, can you tryhostname -a(show alias name) andhostname -s(show short host name)?alias | grep hostnameon your system? Because AFAIKhostnameis pretty universal across OSes (*nix, NetWare, Windows, ...)hostname:192.168.2.13$(scutil --get ComputerName 2>/dev/null || hostname).