为什么管重置当前的工作目录? [英] Why pipe resets current working directory?
本文介绍了为什么管重置当前的工作目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
第一个脚本:
$ { mkdir dir; cd dir; pwd; } | cat; pwd;
./dir
.
第二个脚本:
$ { mkdir dir; cd dir; pwd; }; pwd;
./dir
./dir
为什么这个 |猫
对当前目录中的效果?而如何解决呢?我需要的第一个脚本为第二个完全相同的工作。我不想猫
来改变我的当前目录回到。
。
Why this | cat
has an effect on current directory? And how to solve it? I need the first script to work exactly as the second one. I don't want cat
to change my current directory back to .
.
推荐答案
在管道中的每个命令在自己的子shell执行(见
的命令执行环境)。
Each command in a pipeline is executed in its own subshell (see Command Execution Environment).
另请参见分组命令的:
{}
{ list; }
配售花括号之间的命令列表原因列表是
在当前shell环境中执行。无子shell创建。
Placing a list of commands between curly braces causes the list to be executed in the current shell context. No subshell is created.
这篇关于为什么管重置当前的工作目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文