当您将输入从一个流程或作业“管道”到另一个流程或作业时,您还将生成另一个流程。据说这两个作业都是调用它们的主进程(通常是运行终端仿真器的进程)的“子代”。
# 2 process are run here
# first job: echo
# second job: ls
echo "/home/" | ls
在查看zsh
的来源时,看起来作业的cwd
与作业执行后的原始cwd
不同,它将通知用户一条消息像(pwd now: foo)
。这有助于确保用户确切知道目录树中的位置,这在他们可能不打算这样做时特别有用。以下摘自jobs.c,其中cwd
(称为pwd
)在打印之前比较了cwd
(称为pwd
) (pwd now: foo)
消息。如果它们不同,则打印消息,如果相等,则不打印消息。
if ((lng & 4) || (interact && job == thisjob &&
jn->pwd && strcmp(jn->pwd,pwd))) {
doneprint = 1;
fprintf(fout,"(pwd %s: ",(lng & 4) ? "" : "now");
fprintdir(((lng & 4) && jn->pwd) ? jn->pwd : pwd,fout);
fprintf(fout,")\n");
fflush(fout);
}
当您将某些内容传送到ch
中时,您正在子进程中更改cwd
,并且绕过了一些在直接调用cd
时隐藏此消息的常规检查。否则,以相同的方式cd
个单词。
# changes directories into ./test
echo "test" | cd
# (pwd now: /path/to/test)
# changes directory to home
echo | cd
# (pwd now: /home/<username>)
# calling this again will not echo the message,since the cwd is already
# the home directory and no change occurs
echo | cd
关于将cwd
更改为主目录(~
)的原因,是由于在没有给定路径作为参数的情况下cd
的行为。与许多Linux命令不同,cd
不会从stdin
读取要进入的路径。因此,将cd
中的管道填充到stdin
中只会填充cd
,但是该内容将被忽略。由于这种向cd
传递的方式与仅调用cd
的方式相同。
# these next lines produce the same behavior
echo path/to/dir/test | cd
cd
cd
没有收到要移动的路径时,它将把您移动到您的主目录(在Linux系统上称为~
)
# each of these lines produce the same behavior
cd /home/<username>
cd ~
cd
本文链接:https://www.f2er.com/1688387.html