Sujet : Re: Command Languages Versus Programming Languages
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.unix.shell comp.unix.programmer comp.lang.miscDate : 30. Mar 2024, 01:30:53
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <uu7mfu$jjrf$1@dont-email.me>
References : 1 2 3 4 5
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 30.03.2024 00:51, Lawrence D'Oliveiro wrote:
On Sat, 30 Mar 2024 00:14:42 +0100, Janis Papanagnou wrote:
So what is 'for i in a ; do ... ; done' then in your world?
“for” is just the name of a command, like any other. In POSIX, this one
happens to be built into the shell; it might not in other shells.
'for' is a "reserved word" and part of a "compound command". It's
part of the _shell syntax_! - You get syntax errors like
$ for ; do : ; done
ksh: syntax error: `;' unexpected
And, specifically, "i in a" are *not* arguments of a 'for' command
but also part of the control construct syntax.
But, okay, I see where you're coming from.
Besides the naming, keep in mind that there's a semantical differences
between a "command", a "built-in command", and "shell construct". An
example where you can observe operational differences is:
'/bin/test' and '/bin/['
'test' and '['
'[['
where (for example) the latter does not need quoting.
$ x="Hello world" ; [[ $x == "Hello world" ]] ; echo $?
0
$ x="Hello world" ; [ $x == "Hello world" ] ; echo $?
ksh: [: world: unknown operator
2
$ x="Hello world" ; [ "$x" == "Hello world" ] ; echo $?
0
The distinction is important since there's operational differences
associated with these forms. The same holds for other control constructs
("built-in compound commands"), like 'case', or even simple assignments.
Janis