bug-bash
[Top][All Lists]
Advanced

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

Re: problem anomalies , possibly aliases related


From: Martin D Kealey
Subject: Re: problem anomalies , possibly aliases related
Date: Thu, 20 Jul 2023 16:22:38 +1000

Hi Alex

Aliases are not functions, and they don't work the same way.

A function is like a separate script, except that it runs in the same
process & context as the caller. Its meaning is determined as the script
RUNS.
An alias is quite different: it replaces tokens while the script is being
PARSED.

In particular,
alias A='B ; C'
D && A
will replace `A` with `B ; C` to get `D && B ; C` which is THEN parsed into
the equivalent of:
{ D && B ; } ; C

(Same if you use a line break instead of a semicolon.)

The output of `set -x` reflects the structure of the code, not the literal
text. We expect it to exclude comments, extra blank lines, and names of
aliases where they are used.

Unless you actually need to modify how a script is PARSED, don't use
aliases; use functions instead.

-Martin

PS: please use structure-indicative indentation when showing examples.


reply via email to

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