Sample Header Ad - 728x90

Why can a list within a group be terminated with a space instead of a semicolon/newline as defined in the manual?

5 votes
1 answer
109 views
I am using the following version of the bash:
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
[Man bash](https://www.man7.org/linux/man-pages/man1/bash.1.html#SHELL_GRAMMAR) states the following for the "group" compound commnad: > { list; } > > list is simply executed in the current shell environment. > list must be terminated with a newline or semicolon. This > is known as a group command. The return status is the exit > status of list. Note that unlike the metacharacters ( and > ), { and } are reserved words and must occur where a > reserved word is permitted to be recognized. Since they do > not cause a word break, they must be separated from list by > whitespace or another shell metacharacter. Thus, according to it, the following two are valid { echo ok; } and { { echo ok; }; }. In second case I have a group within a group. However, what confuses me is the following example: { { echo ok; } }. It also works, but how is that possible? According to the manual, the list within { and } must end with a semicolon (or newline). In my example inner group (which is the list for the outer group) does not end with a semicolon (or newline), but with a space (we should have ; after the first }). Why does this work?
Asked by Yakog (517 rep)
Mar 14, 2025, 06:28 PM
Last activity: Mar 15, 2025, 11:37 AM