At startup:
{ mkdir -p dir; cd dir; pwd; } | cat; pwd
OR
{ mkdir -p dir; cd dir; pwd; } | date
OR
{ mkdir -p dir; cd dir; pwd; } | ls
You execute a group of commands on the LHS channel in the sub-shell and, therefore, the change dir does not appear in the current shell after the completion of both commands (LHS and RHS).
However, at startup:
{ mkdir -p dir; cd dir; pwd; }; pwd;
Between them there is not a single command inside the curly braces, and pwd outside the curly braces is executed in the current shell , so you get a modified directory.
PS: Also note that this line:
( mkdir -p dir; cd dir; pwd; )
It also will not change the current directory in the current shell, because the commands inside the square brackets are executed in a subclass, while the curly braces are just used to group.
anubhava
source share