[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Shell Grammar man page

From: Mike Jonkmans
Subject: Shell Grammar man page
Date: Mon, 22 Feb 2021 14:11:48 +0100


It seems some things are missing in the bash manual.
Notably definition of command and placements of coproc- and function-definition.

The section 'SHELL GRAMMAR' describes:
- simple-command
- pipeline
- list
- compound-command
- coproc
- function-definition

Simplified, a pipeline is:
        [ ! ] command1 [ | command2 ]

A list is a sequence of pipelines separated by ;, &, &&, or ||
and optionally terminated by ;, & or NL.

Within the list description, the and-list and or-list are described as:
        and-list: command1 && command2
        or-list: command1 || command2
Though the text says that and/or-lists are sequences of pipelines
(separated by && or ||).

That is slightly inconsistent.
A pipeline can be reduced to a command.
I don't think a command can be a pipeline nor a list.
In that case, the and/or list should read:
        and-list: pipeline1 && pipeline2
        or-list: pipeline1 || pipeline2

These are valid:
        : | { :; }
        list: pipeline: command1 s|' command2
        command1: simple-command
        command2: compound-command

        { :; } || :
        list: or-list: pipeline1 || pipeline2
        pipeline1: command : compound-command
        pipeline2: command: simple-command

        :() if [ x = x ]; then echo; fi </dev/null && echo
        ## not useful as the function definition will not be available
        ## it is here to show a relatively unkown part of the grammar
        list: and-list: pipeline1 && pipeline2
        pipeline1: command: function-definition
        pipeline2: command: simple-command

This is not valid:
        : & && :
        list: and-list != list && simple-command

It seems command can be:
- simple-command
- compound-command
- function-definition
- coproc
A command can not be a list nor a pipeline.

[ Start of the grammar would be a list. ]

But maybe a command can be a pipeline, otherwise this is not parsable:
        ! ! :
        list: pipeline: ! command
        command: pipeline: ! simple-command

Or the, simplified, pipeline definition should be:
        pipeline: [ ! ]* command1 [ | command2 ]*

Any thoughts?

Regards, Mike Jonkmans
(sidenote: 'time time ls' is only printing time once - nice)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]