[TUHS] Use of "{}" in the Shell?
Rich Salz via TUHS
tuhs at tuhs.org
Wed Aug 5 06:36:01 AEST 2026
Because shell variables are expanded before execution
On Tue, Aug 4, 2026, 4:09 PM Warner Losh via TUHS <tuhs at tuhs.org> wrote:
> On Tue, Aug 4, 2026, 2:08 PM Warner Losh <imp at bsdimp.com> wrote:
>
> >
> >
> > On Tue, Aug 4, 2026, 1:23 PM 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
> >
> >
> > Because {} doesn't fork a shell.
> >
>
> Oh () hiding in there. N/m
>
> Warner
>
> >
> > Warner
> >
> >
> >> > On Aug 3, 2026, at 11:47 PM, Arnold Robbins via TUHS <tuhs at tuhs.org>
> >> wrote:
> >> >
> >> > Warner Losh via TUHS <tuhs at tuhs.org> wrote:
> >> >
> >> >> I've not examined the source to Thompson shell closely to know if it
> >> >> secretly does this (and that's why Steve Bourne implemented it), or
> if
> >> >> that's something Bourne invented.
> >> >
> >> > Braces are also allowed where "do" and "done" are.
> >> >
> >> > I have always suspected, but never bothered to verify, that this is
> >> > the case so that shell scripts could look more like C if one wanted
> >> > them to. For example, in Bash:
> >> >
> >> > $ for ((i = 1; i <= 3; i++))
> >> > > {
> >> > > echo $i
> >> > > }
> >> > 1
> >> > 2
> >> > 3
> >> >
> >> > Arnold
> >>
> >>
>
More information about the TUHS
mailing list