我知道我可以使用cd
命令在bash中更改我的工作目录。暂时在bash中改变当前工作目录以运行命令
但如果我这样做的命令:
cd SOME_PATH && run_some_command
然后工作目录将被永久改变。有没有办法像这样暂时改变工作目录?
(cd SOME_PATH && exec_some_command)
演示:
$ pwd
/home/abhijit
$ (cd /tmp && pwd) # directory changed in the subshell
/tmp
$ pwd # parent shell's pwd is still the same
/home/abhijit
为什么不保持它的简单** CD SOME_PATH && run_some_command && CD - **最后一个命令将带你回到过去的PWD目录。 – Sahil