From mboxrd@z Thu Jan 1 00:00:00 1970
X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org
X-Spam-Level:
X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID,
DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham
autolearn_force=no version=3.4.4
Received: (qmail 20123 invoked from network); 30 Dec 2022 22:13:26 -0000
Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368)
by inbox.vuxu.org with ESMTPUTF8; 30 Dec 2022 22:13:26 -0000
ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1672438406;
b=aaX0Ogbj0Chs9G1mSi8eu4I9pzzgHquon+S+idzt/KS8PBvW61OwIkVaEw5Xz4ODyUmNCXVqwm
APA2+7fBWXxx0ubkNtvvq7b0bVJbk/zhbPr2SLBKThthSJ61q6cNjIhZQrn6ib6hbGTT4rg0mE
bfmE4uEEzs/lzVXHhMGzAaj3LIzN8XBk76URlZj31i9GGLmwmZXtpMjX+LN5Z5mbZLpWMo7JO7
pV/JioccCiaZu/ITrrzBPdTWvfeLlna50kgFUH0viWQlqgO23Vpd5KHPoNwxGE3PJAMVe5YMbE
TwypdvGYB72+qNkxrzbd7LNtCIkpxzIqAllbrgpHaK3hYg==;
ARC-Authentication-Results: i=1; zsh.org;
iprev=pass (smtpq1.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.96;
dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256;
dmarc=pass header.from=ntlworld.com;
arc=none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1672438406;
bh=Z0CFerB9dtT9RZXsmx/8G4cJmeR9XBGYfDq4v7BGiKY=;
h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help:
List-Id:Sender:Content-Transfer-Encoding:MIME-Version:Content-Type:
References:In-Reply-To:Date:To:From:Subject:Message-ID:DKIM-Signature:
DKIM-Signature;
b=kA5u4rMK4Zb59FX267Bw0vRTSZM9u11kufpEElhn6Kls1R/WO2H43Ggklujxi+zNZGzwOITV4V
lkB9bIvwAK13wPi4ErEZTjHJlEX8pIBBXk3Z9evEyjqpBnBuOrqTdIjibguA7loQ+X2/4CNQsX
8oc+xUamZC2VmfWXImfDefDOaxKoo7so1WnnH8EPbatm4r3fjxONv5LD8WbQaC0v2jKKXmJvIU
hbeIeBVbKf9982Bp+DdHty3O0jTL1RlobtONDSa4p67JaN7IAiA6RTUSnKELGf/Xzghfou7BPU
rGK8NcCE2RdFmgeXFe5CEdsE8n6Zwh/DvmnlYVl2luEnwQ==;
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org;
s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:
List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding:
Mime-Version:Content-Type:References:In-Reply-To:Date:To:From:Subject:
Message-ID:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From
:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID;
bh=7mUta4KUKbF1WpXg+KctB/ClR6P6hlHB81uLUMJqHL4=; b=PSIqp2KTAtgAvV1xSFVRTwzwwn
JuiARBrHpQ7wSf97SyJ//Xmp8uRJ5g7YY7QkPY7E0W6Lcb1kn5O6nqeDs3DrCWyKf6pVKOjA7cYbH
2EgQcHDkEwP3bugb+G0EK3ThwDt/TPKg9RP17PBz7j031yHnt7dSorEgA6FNcGibut392WxVOdVQF
kh5tfobrsYCFTOmaC3ZBAaX/VxcV7xpFCdlXxH+Gj3xTGs1QlrSS6/wREhwr0cT2cYV/Lk8gJUacE
flmVYUVXsY8iOKecKZ4GkkTCTQ0QH1vFGEodAwkkFIuKaRNOE7yUKq9EyYoy4WR4d4etGkq/k5SBo
EC8kEitw==;
Received: by zero.zsh.org with local
id 1pBNcz-0009xl-Ca;
Fri, 30 Dec 2022 22:13:25 +0000
Authentication-Results: zsh.org;
iprev=pass (smtpq1.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.96;
dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256;
dmarc=pass header.from=ntlworld.com;
arc=none
Received: from smtpq1.tb.ukmail.iss.as9143.net ([212.54.57.96]:49552)
by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256)
id 1pBNRQ-0008yy-W0;
Fri, 30 Dec 2022 22:01:29 +0000
Received: from [212.54.57.110] (helo=csmtp6.tb.ukmail.iss.as9143.net)
by smtpq1.tb.ukmail.iss.as9143.net with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
(Exim 4.90_1)
(envelope-from
)
id 1pBNRQ-0001Ko-Qp
for zsh-users@zsh.org; Fri, 30 Dec 2022 23:01:28 +0100
Received: from pws-Zeus ([82.1.229.179])
by cmsmtp with ESMTPA
id BNRQpWA82ZHwlBNRQpjPjh; Fri, 30 Dec 2022 23:01:28 +0100
X-SourceIP: 82.1.229.179
X-Authenticated-Sender: p.w.stephenson@ntlworld.com
X-Spam: 0
X-Authority: v=2.4 cv=M9WLaQ8s c=1 sm=1 tr=0 ts=63af5fb8 cx=a_exe
a=W4rGJ7PGCSRRUvufKHO8Dg==:117 a=W4rGJ7PGCSRRUvufKHO8Dg==:17
a=FnXrdotqt3JNNtNl:21 a=IkcTkHD0fZMA:10 a=sHyYjHe8cH0A:10
a=9_-vIO__4KGq2XfbCFwA:9 a=QEXdDO2ut3YA:10 a=UUNeL2o2IhLCBrNJZalf:22
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ntlworld.com;
s=meg.feb2017; t=1672437688;
bh=7mUta4KUKbF1WpXg+KctB/ClR6P6hlHB81uLUMJqHL4=;
h=Subject:From:To:Date:In-Reply-To:References;
b=NyxwKZnvmPik+XSYn4RJ2ea9Lpa0uoBj2q5VALrTYLJ/8GyT9gVslCIumpcX9cdia
38Fvl2mOPce4ch8iG/nJI8996FR19kIv3obV3n7TJZ9BZAPtu8iCOrGYpk9INXM24V
g1igit+nsMi+2MGCQ0xi86b0LAzy4tS5Z70sP1F2/O5HHTsg6wbV3DWPLXxYYUc35i
k0HfVuriyPYf7wbzLHPumQ4zGEi4waLWUKgpDCb12sdCYtMEQrv6QH/Q8t7CHjkzIq
y/YgLmYNH940t2EOdUsqWtJ09lF+58jAt5u+A8IypRJacrMu/NIldLeiww17NvKZv2
mGHLdP5mMZXCw==
Message-ID: <2f8d30f569ab6eae90a8ea1bda689907ecb49495.camel@ntlworld.com>
Subject: Re: When it is allowed to use alias after defining it?
From: Peter Stephenson
To: zsh-users@zsh.org
Date: Fri, 30 Dec 2022 22:01:28 +0000
In-Reply-To:
References:
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.2
Mime-Version: 1.0
Content-Transfer-Encoding: 8bit
X-CMAE-Envelope: MS4xfOd6p5R6dbDKcz4qS8a8/7aVDUlcVPgBf/3l+yZaRzxyEw4D9YHLx+BOxWjEGc4yIkoHe1BE3YuWU2hADmECNXJvMzk/sNkRIlzbUFOaLfgN2E4JnBCn
8Of13dlNr9XGloBMm6h6JONT1bzMLyYZn3PSGZYCfePU/iRI2D7R5aHQ5/s8OyROZdtyq58tGL8Zog==
X-Seq: 28612
Archived-At:
X-Loop: zsh-users@zsh.org
Errors-To: zsh-users-owner@zsh.org
Precedence: list
Precedence: bulk
Sender: zsh-users-request@zsh.org
X-no-archive: yes
List-Id:
List-Help: ,
List-Subscribe: ,
List-Unsubscribe: ,
List-Post:
List-Owner:
List-Archive:
On Fri, 2022-12-30 at 21:45 +0000, Sebastian Gniazdowski wrote:
> I was thinking that in current file it is impossible to use an alias – only should work in sourced sub-script.
>
> So:
> alias q=pushd
> # Expected to not work
> q
> # Expected to work
> source ./using-q.zsh
>
> The script is fine to use q. Is that the truth? Because I'm using
> aliases in the same file, only if it is at some proximity from
> definition. What are the rules here?
It's a question of when the execution of the line happens in relation to
parsing it, and also of the fact that expanding an alias happens very
early at the point where the line is read in.
When reading a script, the shell reads one line at a time --- if the
line contains an unfinished complex command, it will continue reading
until that's finished. Then it executes it, before reading anything
else, so if the line was an alias definition that's available from then
on. That's pretty much the same as what happens in an interactive
shell, in fact it's the same internal logic --- the difference between
the two occurs at the point where the shell gets input, where it decides
whether it's blindly going to read a line or invoke the editor.
So complex commands are the key case where the effect is delayed. This
obviously includes functions; the classic case where you *can't* rely on
an alias being defined is:
fn() {
alias q=pusehd
q
}
since the function is defined in one go before the alias is defined
within the function. Because aliases are resolved on input, the q is
treated as a normal command within the function.
Although this is a logical consequence of shell input, it's certainly
not an obvious one.
pws