The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
problem in tar command sais UNIX for Dummies Questions & Answers 1 05-12-2008 08:20 AM
Problem with tr command a-z 0-9 kodermanna UNIX for Advanced & Expert Users 1 04-12-2008 01:32 AM
problem with tr command ravi raj kumar UNIX for Advanced & Expert Users 2 07-02-2007 03:41 AM
problem with dd command or maybe AFS problem Anta Shell Programming and Scripting 0 08-25-2006 07:10 AM
Problem with cut command amon Shell Programming and Scripting 7 02-15-2006 08:22 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 07-05-2008
vidyadhar85's Avatar
The Tutor
 

Join Date: Jun 2008
Location: INDIA
Posts: 537
Question problem in CD command

hello guys,,
here is my problemia have written a code as below

var="vi"
if [ "$var" = "vi" ] ; then
cd <some path>
echo $PWD
fi

my problem is after exicution of this code the cintrol will return to the path from where its exicuted
but how can i modify so this so that after exicution of this script the control will go to cd <some path>

i mean suppose first /home/vidy>
after /home/vidya/fns/pd/r>

is it possible???
suggest some answer!!!!
Reply With Quote
Forum Sponsor
  #2  
Old 07-05-2008
Registered User
 

Join Date: Jul 2008
Location: Texas
Posts: 60
This problem you're having is due to inheritance. When you run/execute your script, it inherits a copy of the current environment. Anything you do in the script affects your inherited environment but not that of your parent.

What you need to do is source your script instead of running it. When you source it, it runs under your current shell so changes that you make will be reflected in your environment when the script finishes executing.

Assuming your script is named test.sh, and you're in the directory where the script resides, source it as follows:
> . ./test.sh

If you do this, when execution is complete, you will be in whatever directory was specified by the "cd <some path>" command.
Reply With Quote
  #3  
Old 07-07-2008
vidyadhar85's Avatar
The Tutor
 

Join Date: Jun 2008
Location: INDIA
Posts: 537
thanku very much this helped a lot.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:30 PM.


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