The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Passing environment variables to parent shells konndanley UNIX for Dummies Questions & Answers 3 08-04-2007 02:15 PM
parent shell pid maheshwin Shell Programming and Scripting 4 01-30-2007 09:19 PM
How to pass CSH variables up to the parent? ElCaito Shell Programming and Scripting 0 11-29-2006 11:30 PM
How to know parent script raki SUN Solaris 1 06-06-2006 01:03 AM
can you change direcotry using variables? jsalz638 Shell Programming and Scripting 4 07-06-2004 05:09 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-17-2008
Registered User
 

Join Date: Dec 2007
Posts: 14
How to change parent shell's variables?

I have a question about how to change variables in parent shell.

My script, test.sh, is below:

#!/bin/sh
# test.sh
PATH=.

The commands I ran for test:

$ echo $PATH
.:/usr/bin:/usr/sbin:/usr/local/sbin:
$ sh test.sh
$ echo $PATH
.:/usr/bin:/usr/sbin:/usr/local/sbin:

Note that when I run sh test.sh, the variable PATH was not changed. I know that I can run . test.sh to make it change PATH. But for some reason I have to run sh test.sh. So in this case, how to make child process change the variables in parent process?

Thanks.
Reply With Quote
Forum Sponsor
  #2  
Old 01-17-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,329
The parent shell can't inherit variables from the child but you can run your script in the current shell with (first make your script executable):

Code:
. scriptname
or if you have the source command on your system:

Code:
source scriptname
Regards
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0