diff --git a/NOTES.md b/NOTES.md index f1d1c4b..f033f74 100644 --- a/NOTES.md +++ b/NOTES.md @@ -207,6 +207,29 @@ not remain in effect after the subshell completes. The exit status of this construct is the exit status of LIST. +```c +struct s_cmdgroup; + +typedef union u_cmdgroup_item_inner +{ + struct s_cmdgroup cmdgroup; + struct s_cmdlist cmdlist; +} t_cmdgroup_item_inner; + +typedef struct s_cmdgroup_item +{ + enum e_cmdgroup_item_type type; + union u_cmdgroup_item_inner inner; +} t_cmdgroup_item; + +typedef struct s_cmdgroup +{ + int item_num; + struct s_cmdgroup_item *items; + struct s_redirects *redirections; +} t_cmdgroup; +``` + ### Shell Expansion cf. 3.5 Shell Expansions @@ -389,6 +412,48 @@ bash-5.1$ echo "hello world" > $nonexist bash: $nonexist: ambiguous redirect ``` +Interesting cases: +command group must handle redirections at the scale of the group +pipelines handle piplines +simple commands handle its own file redirections +group redirections may not appear at the start, except for here_doc, which will give a parse error *afterwards* +```shell +bash-5.2$ (echo hello | cat -e > outcat && echo hi) > outgroup +bash-5.2$ cat outgroup +hi +bash-5.2$ cat outcat +hello$ +bash-5.2$ (echo hello | cat -e && echo hi) > outgroup2 +bash-5.2$ cat outgroup2 +hello$ +hi +bash-5.2$ (echo hello > outhello | cat -e && echo hi) > outgroup3 +bash-5.2$ cat outhello +hello +bash-5.2$ cat outgroup3 +hi +bash-5.2$ > outgroup4 (echo hello > outhello | cat -e && echo hi) +bash: syntax error near unexpected token `(' +bash-5.2$ echo bonjour > infile +bash-5.2$ < infile (cat - > outhello | cat -e && echo hi) +bash: syntax error near unexpected token `(' +bash-5.2$ << EOF (cat - > outhello | cat -e && echo hi) +> hello +> EOF +bash: syntax error near unexpected token `(' +bash-5.2$ (cat - > outhello | cat -e && echo hi) < infile +hi +bash-5.2$ (cat - > outhello | cat -e && echo hi) << EOF +> helllo +> EOF +hi +bash-5.2$ cat outhello +helllo +bash-5.2$ (echo coucou | echo hello) > outfile +bash-5.2$ cat outfile +hello +``` + #### Here Documents cf. Bash Reference Manual 3.6.6 Here Documents