Bash shell script run on UNIX command line, does not change current shell environment

Possible duplicate:
Why doesn't "cd" work in a bash shell script?

I am trying to execute ./go_cd bash shell from UNIX command line in my working directory '/ c / My_Objective'. All I expect from the script is to change to the new directory '/ c / My_Objective / project'. The script output indicates that the directory has been changed to "/ c / My_Objective / project", however, when the script finishes executing and returns to the current command line, the directory is still in '/ c / My_Objective'. Why hasn't the directory changed?

Below is a simple bash shell script that I am using as a test.

## current directory is '/c/My_Objective'
cd project
## new directory should now be '/c/My_Objective/project'


Is there a way to get the commands, i.e., 'cd' executed in the new process script, to get back to the original process where I started the 'go_cd' script execution?



source to share

1 answer

Subprocesses do not affect the parent process. If you want your shell script to modify an existing shell, it must be started by an existing shell, for example:





All Articles