On Wed, 21 Jun 2023 09:01:20 -0400 Greg Wooledge <g...@wooledge.org> wrote:
> On Wed, Jun 21, 2023 at 09:54:30AM +0100, Kerin Millar wrote: > > On Wed, 21 Jun 2023 14:11:28 +0530 > > LitHack <litha...@gmail.com> wrote: > > > > > But why this not worked in zsh. > > > > I don't use zsh. A fairly plausible explanation would be that its alias > > builtin ignores the request to declare an alias, if issued in a subshell. > > I don't normally use it either, so let's try it and see: > > unicorn:~$ zsh > greg@unicorn ~ % alias > which-command=whence > greg@unicorn ~ % (alias) > which-command=whence > greg@unicorn ~ % (alias x=date; alias) > which-command=whence > x=date > > The alias definition occurs in the subshell, but the output of the "alias" > command differs from bash's. Running zsh's "alias" output as a command > would only give you a variable assignment, not an alias assignment. Cf. > bash: > > unicorn:~$ alias > alias cls='tput clear; tput cup 99 0' > [...] > > Bash's output includes the "alias" command name before the x=y bits. > Zsh's outpt does not. Ah. I had to look it up to be certain but it transpires that this is the POSIXLY correct thing to do, so to speak. Bash does the same with -o posix. -- Kerin Millar