shell builtin with redirection shell builtin with redirection shell shell

shell builtin with redirection


Links of a pipeline are run in forked subshells.

In bash, you can print the PID of the current process with $BASHPID, so something like:

self(){ echo $BASHPID; } ; self ; self >&2 | self; self

should give you something like:

12849128511285212849

with the middle two PIDs being different than the first and the last (the mother shell) (in some shells, the first or the last link is run in the mother shell, but not in bash).

Changing the current directory or exporting a value in a subshell won't affect the parent shell in any way whatsoever.


I think you're confusing pipes '|' with semicolons ';' when building toolchains. Pipes are for passing stdout of one command into stdin of another.Semicolons are for running one command after another in the same shell.

Thus in order to enter some directory and list its content you should do this:

cd somedir; ls

usually in Linux all processes of a pipeline are started at the same time in subshells, with their streams appropriately connected, and managed by the scheduler together with all other processes running on the machine. Their outputs are reconnected through buffers and synchronized

That's why you don't see changes of export command because variable stayed in child's subshell.