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 - 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 02-25-2012, 04:58 PM   #1
KenHorse
LQ Newbie
 
Registered: Dec 2004
Posts: 21

Rep: Reputation: 1
OK, I'm feeling really stupid....export within a script


Assume the following script:

Code:
#! /bin/bash

if [ "$TEST" = "YES" ] ; then
  export TEST=NO
fi
I set the variable:

[murphy@localhost]$ export TEST=YES

run the script (yes, it's already executable)

[murphy@localhost]$ . ./test

and finally

[murphy@localhost]$ echo $TEST
YES

Ok, what am I doing wrong?
 
Old 02-25-2012, 05:00 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,223

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
I carried out those exact steps, and I got the expected output of NO.
 
Old 02-25-2012, 09:10 PM   #3
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
export makes the shell variable's value available to children. Since you're exporting a variable within a shell script (which is a child of your interactive shell), it will only be available to that script and its children. Not its parent.

---

Oh, I just noticed that you're sourcing the script in to your interactive shell. In that case, I agree with dugan. Those steps produce the "NO" output for me too.

Last edited by anomie; 02-25-2012 at 09:12 PM.
 
  


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
export call in bash script Donald1000 Linux - Software 10 03-12-2009 08:03 PM
How can I export my variables from a script? HGeneAnthony Debian 2 05-20-2006 04:47 PM
export in a script movitto Linux - Software 3 08-27-2004 12:37 AM
feeling stupid, cant find thread. kev82 General 9 09-24-2003 12:34 PM
Confused and feeling stupid fossean Linux - General 9 12-03-2001 08:14 PM

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

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