LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-03-2008, 03:50 PM   #1
Zebe
LQ Newbie
 
Registered: Jun 2004
Distribution: Ubuntu
Posts: 13

Rep: Reputation: 0
Create a custom environment variable that stores hostname


Hi,

I'm trying to figure out how I can create a custom environment variable that contains the value of the hostname command.

I'd like to set this variable in .cshrc so I can use the variable to set different paths depending on the system I am logged into...

I was wondering if anyone has done this before?

Thanks for any help. I appreciate it.
 
Old 09-03-2008, 03:52 PM   #2
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 32
There should already be one set up for you to use under $HOSTNAME

Verify with this:

Code:
echo $HOSTNAME
 
Old 09-03-2008, 03:54 PM   #3
Zebe
LQ Newbie
 
Registered: Jun 2004
Distribution: Ubuntu
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by CRC123 View Post
There should already be one set up for you to use under $HOSTNAME

Verify with this:

Code:
echo $HOSTNAME
That's the problem... some systems that variable exists, and on others it is undefined... but every system can run the hostname command fine. So I was thinking I could just create my own variable to compare from that has the value of the hostname command in it...
 
Old 09-03-2008, 03:58 PM   #4
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 32
Oh ok, sorry

Here's how:

Code:
export YOUR_VARIABLE=`hostname`
or
export YOUR_VARIABLE=$(hostname)
place that in rc script on each system.
 
Old 09-03-2008, 04:05 PM   #5
Zebe
LQ Newbie
 
Registered: Jun 2004
Distribution: Ubuntu
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by CRC123 View Post
Oh ok, sorry

Here's how:

Code:
export YOUR_VARIABLE=`hostname`
or
export YOUR_VARIABLE=$(hostname)
place that in rc script on each system.
So would I be able to add that to .cshrc? I added what you have listed (both cases) and I keep getting undefined variable...
 
Old 09-03-2008, 04:14 PM   #6
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 32
My bad, I didn't test it for csh. In csh, to set variable, do this in .cshrc:

Code:
set YOUR_VARIABLE=`hostname`
You have to add this to the .cshrc scripts of all the servers.
 
  


Reply

Tags
cshrc, hostname



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Environment Variable linux_linux Linux - Newbie 4 03-20-2008 10:16 PM
Environment variable vedanu Programming 1 05-17-2007 07:20 AM
create new environment variable ctlqt12 Linux - Newbie 5 05-10-2006 04:26 AM
How to create new permanent environment variable in Red hat Linux? halturata Linux - Newbie 2 04-10-2006 10:38 AM
hostname command vs. $HOSTNAME env. variable Silly22 Linux - Networking 2 03-29-2002 05:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:09 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