mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
notes: some notes about the implementation of cmdgroup
This commit is contained in:
parent
c73884e43a
commit
8f919b33df
1 changed files with 65 additions and 0 deletions
65
NOTES.md
65
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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue