-   Linux - Newbie (
-   -   Difference between $HOSTNAME and $(hostname) (

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


$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?


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.

[tw296@bevelle ~]$ DATE=Thursday # define a variable DATE
[tw296@bevelle ~]$ echo $DATE # display the variable we just defined
[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 08:35 AM.