It's a quite simple asked question I think: What are the key differences between using environment variables just like $HOSTNAME and `hostname`. Where is which appropriate, why are there two possibillities to represent them?
An environment variable is set once and for all (for a given process; when a process launches another, the child inherits the parent's environment). So accessing
In the case of
There's often (but not always) a
It is appropriate to depend on the commands which fetch the current value than the variables which can get stale over a period of time in the unattended sessions.
I think its clear that
Well, in short, output of the commands
If you are curious to know how does shell gets $HOSTNAME inherited, then its proper to know that shell reads its global initialization (rc) files like /etc/profile (or /etc/bashrc) which has this variable defined from again output of
(It is also important to know that programs other than shell without prior executing