[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: aliases sometimes not expanded even with expand_aliases set
From: |
Ian Dall |
Subject: |
Re: aliases sometimes not expanded even with expand_aliases set |
Date: |
Thu, 17 Oct 2024 10:04:37 +1030 |
User-agent: |
Evolution 3.52.4 (3.52.4-1.fc40) |
Thanks for that.
It is certainly confusing that you can do "alias -p" inside the
compound statement and have it print out the alias you think you have
defined, but not have it work. But given that bit of the manual, I can
see why that would be.
On Sat, 2024-10-12 at 15:18 -0400, Chet Ramey wrote:
> On 10/12/24 9:31 AM, ian@beware.dropbear.id.au wrote:
>
> > Bash Version: 5.2
> > Patch Level: 26
> > Release Status: release
> >
> > Description:
> >
> > In the following script, the first alias fails with "comand not found"
> > but the second works.
>
> This is covered in the manual (bash.1):
>
> Bash
> always reads at least one complete line of input,
> and all lines that make up a compound command,
> before executing any of the commands on that line or the compound command.
> Aliases are expanded when a command is read, not when it is executed.
> Therefore, an
> alias definition appearing on the same line as another
> command does not take effect until the shell reads the next line of input,
> and an alias definition in a compound command does not take
> effect until the shell parses and executes the entire compound command.
> The commands following the alias definition
> on that line,
> or in the rest of a compound command,
> are not affected by the new alias.
> This behavior is also an issue when functions are executed.
> Aliases are expanded when a function definition is read,
> not when the function is executed, because a function definition
> is itself a command.
> As a consequence, aliases
> defined in a function are not available until after that
> function is executed.
>
>
>
> --
> ``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/