LinuxQuestions.org
Visit Jeremy's Blog.
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, 05:58 PM   #1
KenHorse
LQ Newbie
 
Registered: Dec 2004
Posts: 5

Rep: Reputation: 0
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, 06:00 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: Slackware
Posts: 7,004

Rep: Reputation: 2528Reputation: 2528Reputation: 2528Reputation: 2528Reputation: 2528Reputation: 2528Reputation: 2528Reputation: 2528Reputation: 2528Reputation: 2528Reputation: 2528
I carried out those exact steps, and I got the expected output of NO.
 
Old 02-25-2012, 10: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 10:12 PM.
 
  


Reply


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


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

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration