hayne
04-10-2005, 02:36 AM
There is nothing wrong with your script.
What is wrong is your expectations of what a script should do.
A shell script runs in a new instance of the shell - i.e. a sub-shell. When you change directory in your script, you are only changing the current directory of that sub-shell. And when the script is finished, the sub-shell exits and is no more.
If you want to change the environment of the current shell, you need to use the "source" command to run the script. In bash, the "source" command is the 'dot' operator (.).
E.g.:
. gotoDocuments
There is no need for a script that you will be sourcing (like above) to be executable.
What is wrong is your expectations of what a script should do.
A shell script runs in a new instance of the shell - i.e. a sub-shell. When you change directory in your script, you are only changing the current directory of that sub-shell. And when the script is finished, the sub-shell exits and is no more.
If you want to change the environment of the current shell, you need to use the "source" command to run the script. In bash, the "source" command is the 'dot' operator (.).
E.g.:
. gotoDocuments
There is no need for a script that you will be sourcing (like above) to be executable.
