Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-14-2005, 04:55 PM   #1
LQ Newbie
Registered: Jun 2005
Posts: 12

Rep: Reputation: 0
environment variables


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

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
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911
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.

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

Rep: Reputation: 66
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
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?


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
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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:11 PM.

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