LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Difference between $HOSTNAME and $(hostname) (https://www.linuxquestions.org/questions/linux-newbie-8/difference-between-%24hostname-and-%24-hostname-783661/)

masatheesh 01-21-2010 12:10 AM

Difference between $HOSTNAME and $(hostname)
 
Can anyone please tell me the difference between $HOSTNAME and $(hostname)?

Tinkster 01-21-2010 12:13 AM

Sure.

$HOSTNAME is a shell variable.

$(hostname) runs the command 'hostname' in a sub-shell.

masatheesh 01-21-2010 12:59 AM

can you please tell me example for importance of these?

Thanks

paulsm4 01-21-2010 01:16 AM

Do you understand what Tinkster was trying to explain?

"$HOSTNAME" is just a variable.

"$(hostname)", in contrast, runs the program "hostname" and makes its contents (the string consisting of your computer's host name) available to the shell. One of the things you could do with it is assign those contents (the "hostname" string) to a new variable.

cantab 01-21-2010 01:39 AM

Let us take another example.
Code:

[tw296@bevelle ~]$ DATE=Thursday # define a variable DATE
[tw296@bevelle ~]$ echo $DATE # display the variable we just defined
Thursday
[tw296@bevelle ~]$ echo $(date) # display the output of the command 'date'
Thu Jan 21 07:37:23 GMT 2010


masatheesh 01-21-2010 02:17 AM

Thanks a lot to everyone


All times are GMT -5. The time now is 12:36 AM.