LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-21-2010, 12:10 AM   #1
masatheesh
Member
 
Registered: Aug 2007
Distribution: CentOS 5.0,CentOS 5.5
Posts: 47

Rep: Reputation: 15
Difference between $HOSTNAME and $(hostname)


Can anyone please tell me the difference between $HOSTNAME and $(hostname)?
 
Old 01-21-2010, 12:13 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Sure.

$HOSTNAME is a shell variable.

$(hostname) runs the command 'hostname' in a sub-shell.
 
Old 01-21-2010, 12:59 AM   #3
masatheesh
Member
 
Registered: Aug 2007
Distribution: CentOS 5.0,CentOS 5.5
Posts: 47

Original Poster
Rep: Reputation: 15
can you please tell me example for importance of these?

Thanks
 
Old 01-21-2010, 01:16 AM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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.
 
1 members found this post helpful.
Old 01-21-2010, 01:39 AM   #5
cantab
Member
 
Registered: Oct 2009
Location: England
Distribution: Kubuntu, Ubuntu, Debian, Proxmox.
Posts: 553

Rep: Reputation: 115Reputation: 115
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
 
1 members found this post helpful.
Old 01-21-2010, 02:17 AM   #6
masatheesh
Member
 
Registered: Aug 2007
Distribution: CentOS 5.0,CentOS 5.5
Posts: 47

Original Poster
Rep: Reputation: 15
Thanks a lot to everyone
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Could someone explain to me the process of adding a hostname? (hostname.domain.com) brynjarh Linux - Server 2 10-18-2009 07:58 PM
Changed hostname during install, now CUPS has wrong hostname on web interface slinx Linux - Software 1 08-07-2009 08:01 PM
after hostname change, syslogd still output previous hostname to messages file tiger2000 Linux - General 3 07-22-2009 09:36 PM
What is the difference between domain name and hostname? davidas Linux - Newbie 9 04-23-2004 01:38 PM
hostname command vs. $HOSTNAME env. variable Silly22 Linux - Networking 2 03-29-2002 05:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration