[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: What code make both `cat < /tmp/1.txt` and `< /tmp/1.txt cat` valid?
From: |
Koichi Murase |
Subject: |
Re: What code make both `cat < /tmp/1.txt` and `< /tmp/1.txt cat` valid? |
Date: |
Tue, 11 May 2021 02:09:42 +0900 |
simple_command_element: WORD
| ASSIGNMENT_WORD
| redirection
2021年5月11日(火) 0:32 Peng Yu <pengyu.ut@gmail.com>:
> I am trying to understand how bash is implemented
> $ < /tmp/1.txt cat
>
> [...]
>
> I see `redirection_list` is just a list of redirection.
>
> redirection_list: redirection
> | redirection_list redirection
>
> But then it should be following `shell_command`. How come
> redirection_list can be anywhere in a command including the beginning?
>
> command:
> ...
> | shell_command redirection_list
"cat" is not "shell_command" but "simple_command". "shell_command" is
some compound commands like for, while, select, etc., and indeed we
cannot write « < file while read line; do something; done » but can
write « while read line; do something; done < file ».
« < /tmp/1.txt cat » is fits the following rules:
command: simple_command
simple_command: simple_command_element
| simple_command simple_command_element
simple_command_element: WORD
| ASSIGNMENT_WORD
| redirection