g****g 发帖数: 1828 | 1 now i understand. it changed the directory, but only within the subshell
that runs the script.
in your example, bash is a subshell of the current shell, say tcsh. whatever
you do in the subshell does not affect the parent shell. |
|
g****g 发帖数: 1828 | 2 Shell scripts are run inside a subshell, and each subshell has its own
concept of what the current directory is. The cd succeeds, but as soon as
the subshell exits, the previous current directory is restored.
One way to get around this is to use an alias instead:
alias up='cd ..'
Then in a bash shell, you can do something like:
bash-3.00$ pwd
/home/myhome
bash-3.00$ alias up='cd ..'
bash-3.00$ up
bash-3.00$ pwd
/home
bash-3.00$ up
bash-3.00$ pwd
/ |
|
v*****r 发帖数: 1119 | 3 You probably didn't include hash pling (#!) in you script and the script was
running in current environment instead of subshell. Add #! line. |
|
|