bug-bash
[Top][All Lists]
Advanced

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

Re: forwarded weirdness report


From: Greg Wooledge
Subject: Re: forwarded weirdness report
Date: Mon, 28 Mar 2022 17:00:11 -0400

On Mon, Mar 28, 2022 at 04:18:05PM -0400, Chet Ramey wrote:
> On 3/28/22 3:06 PM, Martin Schulte wrote:
> > on Mon, 28 Mar 2022 20:34:40 +0200 Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com> 
> > wrote:
> > > https://pastebin.com/raw/T7ZnFapt
> > 
> > Here's a somewhat stripped down version:
> > 
> > $ bash --noprofile --norc -i -c "echo \$BASH_VERSION; shopt -s 
> > expand_aliases ; source <(echo \"alias x='echo hallo'\"); alias; x"
> > 5.1.4(1)-release
> > alias x='echo hallo'
> > bash: x: command not found
> 
> OK, once more from the top.
> 
> The argument to -c is a single command. Bash always reads a complete command
> before executing any of it. The argument string is parsed into a
> compound command: a compound list. Since the entire compound list is parsed
> before executing any of the commands it contains, the `x' is parsed as a
> simple command with no defined alias -- the parsing takes place before
> executing the `alias x=...' command.

And here's a workaround:

unicorn:~$ bash --noprofile --norc -i -c $'alias x="echo hallo"; x'
bash: x: command not found
unicorn:~$ bash --noprofile --norc -i -c $'alias x="echo hallo"\nx'
hallo

Put a literal newline in the -c argument, rather than a semicolon.

Or -- and I know this answer will be rejected, because it's too simple 
and sensible -- stop using aliases in scripts.



reply via email to

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