Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: while alias



On Mon, Nov 7, 2022 at 5:57 PM Pier Paolo Grassi <pierpaolog@xxxxxxxxx> wrote:
>
> Hello, I have the following alias defined:
>
> WI='while {read -r it; ! [[ $? -ne 0 && -z $it ]]}'
>
> that works fine except in command substitution:

Put spaces around your braces.

alias WI='while { read -r it; ! [[ $? -ne 0 && -z $it ]] }'

Aliases in command substitutions are parsed by a complicated dance
requiring that they be expanded and then backtracked over and then
re-parsed.  The character count for the "{" and/or "}" tokens is off
by one for the backtracking step when they don't have surrounding
whitespace.  (Leaving it to PWS, who choreographed this dance number,
to fix the footwork if possible.)




Messages sorted by: Reverse Date, Date, Thread, Author