LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 06-14-2005, 04:55 PM   #1
user_linux
LQ Newbie
 
Registered: Jun 2005
Posts: 12

Rep: Reputation: 0
environment variables


Hi,

I am new to linux and I have the following problem :

I am trying to set the environment variable HOST by typing the following in the command line :

export HOST = `hostname`

It is setting the variable correctly. When I say

echo $HOST

it gives the correct value.

But when I execute the same in a shell script, it does not work.
My shell script is

#!/bin/ksh
export HOST = `hostname`

I even tried without the #!/bin/ksh, but it does not make a difference.

Could somebody please shed some light on this problem?

Thanks in advance.
 
Old 06-14-2005, 05:03 PM   #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
The problem is the way the shell executes a
script ... if you want the variable to exist AFTER
your script has run you need to source it rather
than running it.


Cheers,
Tink
 
Old 06-14-2005, 05:04 PM   #3
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
When you export a variable it will only be available to child processes so unless you run it in your current shell it will not be available once the script exits.

If it is appropriate you could source the script though.
 
Old 06-15-2005, 08:46 AM   #4
user_linux
LQ Newbie
 
Registered: Jun 2005
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks for the replies

my script name is test.ksh. I tried to source it by giving

. test.ksh

at the command line . It says

ksh: .: test.ksh: not found

if i say

source test.ksh

it says

ksh: source: not found

could someone help me please?
 
  


Reply



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
Environment Variables - where do they go!?! iansoundz Linux - General 7 11-17-2005 02:27 AM
environment variables in c++ s3b0 Programming 6 08-27-2004 09:19 AM
when to use environment variables? mark_2811 Programming 2 02-23-2004 06:09 PM
environment variables kakridge Linux - Newbie 1 07-14-2003 06:25 PM
environment variables aethereal Linux - Newbie 7 12-19-2001 09:34 AM

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

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