简体   繁体   English

在bash脚本中永久更改目录

[英]Change directory permanently in a bash script

I'm trying to change directory in a called bash script. 我正在尝试在一个称为bash脚本中更改目录。 For this I tried to use cd command. 为此,我尝试使用cd命令。 But after the script ends current directory is restoring to position before the script call. 但是在脚本结束之后,当前目录将还原到脚本调用之前的位置。 I also tried to change PATH variable but it didn't show any effect too. 我也尝试更改PATH变量,但也没有显示任何效果。 Is there a way to do this? 有没有办法做到这一点?

When you execute a shell script a new shell is started for execution of this script. 当您执行Shell脚本时,将启动一个新的Shell以执行此脚本。 This shell won't affect its parent processes. 此外壳程序不会影响其父进程。

To execute a script in your current shell's context use the source or . 要在当前shell的上下文中执行脚本,请使用source. commands: 命令:

. cd.sh
source cd.sh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM