Help - Search - Members - Calendar
Full Version: Problems With Cd In A Bash Script
Linuxhelp > Support > Technical Support

I'm having problems with a bash script I wrote and have never been able to figure this part out.

Whenever I put a cd <somedir> into a bash script it will change to that dir for the duration of the script. But, when the script is done executing I'm back in the same dir I was when I executed the script.

I assume then that there is some specific command that you need to use in order to make the change stick, I just have never been able to find it.

Any help would be appreciated. Thanks!
because shell script u tried to run is basically a child of the main shell(bash).or to put in other words ..when u execute a shell script those command are issued to a new shell started by the when the shell script exits the change of directory is no longer valid.

so u have to run the script in the current shell and u can do it in this way:
$. ./<shell_script>

this will certainly solve ur problem
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2018 Invision Power Services, Inc.