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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
01-21-2010, 12:10 AM
|
#1
|
Member
Registered: Aug 2007
Distribution: CentOS 5.0,CentOS 5.5
Posts: 47
Rep:
|
Difference between $HOSTNAME and $(hostname)
Can anyone please tell me the difference between $HOSTNAME and $(hostname)?
|
|
|
01-21-2010, 12:13 AM
|
#2
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
Sure.
$HOSTNAME is a shell variable.
$(hostname) runs the command 'hostname' in a sub-shell.
|
|
|
01-21-2010, 12:59 AM
|
#3
|
Member
Registered: Aug 2007
Distribution: CentOS 5.0,CentOS 5.5
Posts: 47
Original Poster
Rep:
|
can you please tell me example for importance of these?
Thanks
|
|
|
01-21-2010, 01:16 AM
|
#4
|
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Rep:
|
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.
|
01-21-2010, 01:39 AM
|
#5
|
Member
Registered: Oct 2009
Location: England
Distribution: Kubuntu, Ubuntu, Debian, Proxmox.
Posts: 553
Rep:
|
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.
|
01-21-2010, 02:17 AM
|
#6
|
Member
Registered: Aug 2007
Distribution: CentOS 5.0,CentOS 5.5
Posts: 47
Original Poster
Rep:
|
Thanks a lot to everyone
|
|
|
All times are GMT -5. The time now is 07:19 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|