[TUHS] Use of "{}" in the Shell?

Arnold Robbins via TUHS tuhs at tuhs.org
Wed Aug 5 22:26:23 AEST 2026


David Barto <barto at kdbarto.org> wrote:

> Then why does
> echo me; echo $$
> ( echo parens ; echo $$ ; )
> { echo brace; echo $$ ; }
>
> Always echo the same pid?
>
> me
> 46999
> parens
> 46999
> brace
> 46999

$$ is the PID of the original shell. The subshell keeps all the
same variables as the parent shell.  Using () instead of {} makes
a difference for something like the classic tar pipeline:

	(cd /home ; tar -cf - arnold) | (cd /newhome ; tar -xpvf -)

to copy a file tree from one place to another.

The `cd's happen in subshells, leaving the parent shell in the
original directory.

HTH,

Arnold


More information about the TUHS mailing list