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.

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...)