Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: $var not expanded in ${x?$var}
- X-seq: zsh-workers 52560
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- Cc: zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: $var not expanded in ${x?$var}
- Date: Tue, 20 Feb 2024 07:05:05 +0000
- Archived-at: <https://zsh.org/workers/52560>
- In-reply-to: <836025199.2014747.1673889335246@mail.virginmedia.com>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>, zsh workers <zsh-workers@xxxxxxx>
- References: <20230113080246.nghigc4givvaomve@chazelas.org> <836025199.2014747.1673889335246@mail.virginmedia.com>
2023-01-16 17:15:35 +0000, Peter Stephenson:
> > On 13/01/2023 08:02 Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
> >
> > $ zsh -c 'echo ${1?$USERNAME}'
> > zsh:1: 1: $USERNAME
> >
> > No quote removal either:
> >
> > $ zsh -c 'echo ${1?"x"}'
> > zsh:1: 1: "x"
> >
> > Doc says:
> >
> > > In any of the above expressions that test a variable and substitute an
> > > alternate WORD, note that you can use standard shell quoting in the WORD
> > > value to selectively override the splitting done by the SH_WORD_SPLIT
> > > option and the = flag, but not splitting by the s:STRING: flag.
>
> In fact the shell does not "substitute an alternate WORD" here, it
> just prints it out, but the difference is easy to miss and expanding it
> seems the right thing to do from other points of view, so I've noted it
> in the doc.
[...]
Thanks.
$ echo ${1?$'a\nb'}
zsh: 1: a\nb
$ print -Prv err '%F{red}BAD%f'
$ a=${1?$err}
zsh: 1: ^[[31mBAD^[[39m
That transformation of newline into \n and other nicezputs'ness
seems undesirable to me though.
It doesn't seem unreasonable for someone to want to provide a
multiline error message or one with terminal escape sequences.
See for instance
https://unix.stackexchange.com/questions/769679/bash-parameter-substitution-with-multi-line-error-message
AFAICT, except for bash doing the IFS-split + join, all other
shells send the expansion verbatim to stderr.
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author