notes: some notes about the implementation of cmdgroup

This commit is contained in:
Khaïs COLIN 2025-03-06 12:37:34 +01:00
parent c73884e43a
commit 8f919b33df
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo

View file

@ -207,6 +207,29 @@ not remain in effect after the subshell completes.
The exit status of this construct is the exit status of LIST. 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 ### Shell Expansion
cf. 3.5 Shell Expansions cf. 3.5 Shell Expansions
@ -389,6 +412,48 @@ bash-5.1$ echo "hello world" > $nonexist
bash: $nonexist: ambiguous redirect 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 #### Here Documents
cf. Bash Reference Manual 3.6.6 Here Documents cf. Bash Reference Manual 3.6.6 Here Documents