Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试在调用的 bash 脚本中更改目录。为此,我尝试使用cd命令。但是在脚本结束后,当前目录将恢复到脚本调用之前的位置。我也尝试更改PATH变量,但它也没有显示任何效果。有没有办法做到这一点?
cd
PATH
当您执行一个 shell 脚本时,会启动一个新的 shell 来执行这个脚本。这个 shell 不会影响它的父进程。
要在当前 shell 的上下文中执行脚本,请使用sourceor. 命令:
source
.
. cd.sh source cd.sh