bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Incorrect alias expansion within command substitution


From: Alex fxmbsw7 Ratchev
Subject: Re: Incorrect alias expansion within command substitution
Date: Sat, 5 Feb 2022 21:44:06 +0100

On Sat, Feb 5, 2022 at 9:39 PM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com> wrote:
>
> On Sat, Feb 5, 2022 at 7:55 PM Chet Ramey <chet.ramey@case.edu> wrote:
> >
> > 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.
>
> so the alias expansion fails at the current command is no alias
> anymore, so alias parsing rules dont apply anymore, .. no ... hmm .. ?
> would make much sense then and i have nothing else to say..

maybe ask about an shopt feature to enable straight alias expansion
when the aliases are following ..
cheers and peace

> btw the printf leet were examples about the other, not to work, not to
> say i tried to code so
>
> > There is no alias expansion because we are
> > not reading a new token and the contents of the arithmetic expansion are
> > treated like a double-quoted string, both disqualifying conditions. We find
> > those two characters, closing the arithmetic expansion, and go on looking
> > for the end of the word. We read a newline, which delimits the token, which
> > is the (shell grammar) WORD `$((  data ))'.
> >
> > After we finish parsing the for loop, we go back to execute it. We run
> > a useless `alias' command, then come to the simple command
> >
> > printf %s\\n $((data))
> >
> > (I removed the spaces from the arithmetic expansion to make it clear that
> > it's one word.)
> >
> > We begin to expand the words in this simple command. When we come to the
> > arithmetic expansion, we take the contents (`data') and run them through
> > the arithmetic evaluator. We get an identifier (`data'), assume it's a
> > shell variable, look up its value (`1 + 2', since that's how the for loop
> > set it) and evaluate that as an expression. It evaluates to 3, and the
> > string "3" becomes the result of the arithmetic expansion.
> >
> > We run
> >
> > printf %s\n 3
> >
> > and get `3' as output.
> >
> > Understand?
>
> yes, now, fail at no more alias so no alias expanded
>
> cheers, thank you much for your kind good effords
>
> > --
> > ``The lyf so short, the craft so long to lerne.'' - Chaucer
> >                  ``Ars longa, vita brevis'' - Hippocrates
> > Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]