Latest LQ Deal: Linux Power User Bundle
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 07-06-2009, 02:42 PM   #1
LQ Newbie
Registered: Jul 2009
Posts: 2

Rep: Reputation: 0
Scope of shell script variables ?

I have a shell script file "", which does this
export TEST_VARIABLE=linux

I call this from a terminal
and after it gets executed when i try to
get the value of the variable TEST_VARIABLE in the same terminal, its empty. What's the scope of this variable ?

$ ./

I need variables that i export in a sh file (and call it from a terminal) to live until the terminal exists. How can i get it ?


Last edited by deepakc; 07-06-2009 at 02:43 PM.
Old 07-06-2009, 03:19 PM   #2
Senior Member
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
you need to source the script:
Old 07-06-2009, 03:53 PM   #3
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Learn something new every day!!!

I had thought that your example would work, but it will not. Here is the relevant quote from "ABS"*:
A script can export variables only to child processes, that is, only to commands or
processes which that particular script initiates. A script invoked from the
command-line cannot export variables back to the command-line environment.
Child processes cannot export variables back to the parent processes that spawned
*ABS = The Advanced BASH Scripting Guide---the favorite boat anchor for scripters with OCD**. Get it (ABS, not OCD) at

**OCD = Obsessive-Compulsive Disorder
Old 07-06-2009, 07:11 PM   #4
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
You may also see the (older) syntax


That's a 'dot' then a 'space', instead of 'source<space>'
Old 07-07-2009, 01:29 AM   #5
LQ Newbie
Registered: Jul 2009
Posts: 2

Original Poster
Rep: Reputation: 0






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
importing variables into shell script? ocicat Programming 5 08-12-2008 04:15 AM
Shell script variables Fredde87 Linux - Newbie 13 11-01-2006 04:35 AM
shell script variables Gary_Menegon Programming 1 10-02-2006 10:28 AM
Passing variables from AWK script to my shell script BigLarry Programming 1 06-12-2004 05:32 AM
Why?? can not use variables with shell script Bassam Linux - General 9 01-27-2004 08:42 AM > Forums > Linux Forums > Linux - Newbie

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