On 2/4/22 6:17 PM, Alex fxmbsw7 Ratchev wrote:
what about this viewing point
aliases can start, $(('s, but not end... this is unlogic
Well, I don't know about `unlogic' but there's an understanding deficit,
for sure.
alias -- \
p='printf %s\\n ' \
assign='assign=$(( ' begin='$(( ' \
for data in "1 + 2"
do
alias -- data="$d "
p begin data ))
done
this works and results 3
OK, let's go through it. I'll gloss over some non-essential details and
simplify others. I'll skip over the bulk of the for loop parsing and just
cover the simple command where alias expansion takes place.
Since `p' is in a command position, it gets alias expanded to
`printf %s\\n '. The lexical analysis restarts, the two words get scanned,
and we start a simple command. The expansion ends with a space, so the next
token (`begin') undergoes alias expansion, gets expanded to `$(( ', and the
lex restarts. We read `$((' and know we're reading the start of a word that
begins with an arithmetic expansion. We keep reading as if we are reading a
double-quoted string, looking for `))', since that's what you do while
reading an arithmetic expansion.