[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: aliases sometimes not expanded even with expand_aliases set
From: |
Chet Ramey |
Subject: |
Re: aliases sometimes not expanded even with expand_aliases set |
Date: |
Sat, 12 Oct 2024 15:18:19 -0400 |
User-agent: |
Mozilla Thunderbird |
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/
OpenPGP_signature.asc
Description: OpenPGP digital signature