The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Change Directory vskr72 UNIX for Dummies Questions & Answers 2 05-26-2008 02:50 AM
how to change permissions in a certain directory? praveen_indramo UNIX for Dummies Questions & Answers 1 03-25-2008 12:07 PM
Change to a new working directory... jagannatha UNIX for Dummies Questions & Answers 5 06-29-2005 10:38 PM
change directory mkan Shell Programming and Scripting 2 02-26-2005 04:55 PM
Change directory command (cd) oscarr Shell Programming and Scripting 4 08-23-2002 08:30 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-10-2002
vadivel vadivel is offline
Registered User
  
 

Join Date: Sep 2001
Location: India.
Posts: 5
Angry change directory

Hi all,

I'm trying to wirte a small shell script in Linux. My script has the flow like,

cmd1
cmd2
cd testdata
cmd3

After exiting the program, the CWD remains the same as where I execute the program. I need it to be changed to the latest updated directory in the program. How can I do this?

Thanks for your help,
Vadivel.
  #2 (permalink)  
Old 06-10-2002
RTM's Avatar
RTM RTM is offline Forum Advisor  
Hog Hunter
  
 

Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
When you execute the script, it starts a child process. The child process ends up in the last directory - not the parent.

To have the parent end up there, you need to run the script differently

sh and ksh
% . ./myscript

csh
$ source ./myscript

This will cause the parent to run the script instead of creating a child process to do it. Beware that some other problems may be created by doing this (just check that your script is not expecting something from the directory you started in...)
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:21 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0