whenever you run a script in your login shell, a new subprocess is generated and the script is executed in sub-shell. After the script completes, the subshell terminates and you return to the login shell. If every time you make cd through a script, the directory changes to the path specified by cd, but by the time the script finishes, you are returned to your shell to enter the working directory from where you started the script.
To overcome this, use
source yourscript.sh
what the source does, it executes the script as a TCL script, i.e. it has the same effect as entering each line on the command line of your login shell, and it runs from there. That way, when the script ends after cd, it stays in that directory.
dig_123 Nov 16 '11 at 12:35 2011-11-16 12:35
source share