On 6/18/25 4:05 PM, Alberto Millán wrote:
First of all, I'd like to thank you for your responses.

Okay, now I understand a little better what's going on with recursion.

In most cases, I can now see what's wrong, but there's one specific case where I can't quite figure out what's wrong.

bash -ic $'alias x=:\nx(){ id;};x'  # This case crash.
bash -ic $'alias x=:;x(){ id;};x'  # This case do not crash.

I understand that the crash is caused by recursion, but I don't quite understand why the expansion of '\n' works as expected (crashes), but it doesn't with the semicolon.

The man page says:

"The  rules  concerning  the  definition and use of aliases are somewhat
 confusing.  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 defi-
 nition  in  a  compound  command  does  not take effect until the shell
 parses and executes the entire compound command."

In this case, the second example is a list, which is a compound command
(see the `Lists' section in the man page).

Bash parses the entire string passed as the argument to -c before executing
any of the commands in it.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/

Reply via email to