zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane@chazelas.org>
To: Peter Stephenson <p.w.stephenson@ntlworld.com>
Cc: zsh workers <zsh-workers@zsh.org>
Subject: Re: $var not expanded in ${x?$var}
Date: Tue, 20 Feb 2024 07:05:05 +0000	[thread overview]
Message-ID: <20240220070505.fd6jfbcdldieqv7u@chazelas.org> (raw)
In-Reply-To: <836025199.2014747.1673889335246@mail.virginmedia.com>

2023-01-16 17:15:35 +0000, Peter Stephenson:
> > On 13/01/2023 08:02 Stephane Chazelas <stephane@chazelas.org> 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


  reply	other threads:[~2024-02-20  7:05 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-13  8:02 Stephane Chazelas
2023-01-16  8:35 ` Daniel Shahaf
2023-01-16 17:15 ` Peter Stephenson
2024-02-20  7:05   ` Stephane Chazelas [this message]
2024-02-20 17:45     ` Bart Schaefer
2024-02-20 19:39       ` Stephane Chazelas
2024-02-21  4:44         ` Bart Schaefer
2024-02-21 19:45           ` Stephane Chazelas
2024-02-21 19:52             ` Bart Schaefer
2024-02-21 20:21               ` Stephane Chazelas
2024-02-22  0:46                 ` [PATCH] unmetafy " Bart Schaefer
2024-02-22  7:23                   ` Stephane Chazelas
2024-02-22  7:55                     ` Metafication in error messages (Was: [PATCH] unmetafy Re: $var not expanded in ${x?$var}) Stephane Chazelas
2024-02-22 17:02                       ` Bart Schaefer
2024-02-22 22:31                         ` Bart Schaefer
2024-02-23  0:49                           ` Bart Schaefer
2024-02-23 19:27                           ` Stephane Chazelas
2024-02-23 22:32                             ` Bart Schaefer
2024-02-23 23:38                               ` Bart Schaefer
2024-02-24  9:47                               ` Stephane Chazelas
2024-02-24 10:36                                 ` Stephane Chazelas
2024-02-25  4:35                                   ` [PATCH] 'bad interpreter' error garbled Bart Schaefer
2024-02-25  5:26                                     ` Bart Schaefer
2024-02-25  2:17                                 ` Metafication in error messages (Was: [PATCH] unmetafy Re: $var not expanded in ${x?$var}) Bart Schaefer
2024-02-25  6:05                                   ` Bart Schaefer
2024-02-25  7:29                                     ` Stephane Chazelas
2024-02-25  8:28                                       ` typeset -<non-ASCII> (Was: metafication in error messages) Stephane Chazelas
2024-02-25  8:35                                         ` Stephane Chazelas
2024-02-25 21:02                                         ` Bart Schaefer
2024-02-23  0:33                       ` Metafication in error messages (Was: [PATCH] unmetafy Re: $var not expanded in ${x?$var}) Bart Schaefer
2024-02-25  5:06                       ` [PATCH] count multibyte and metafied characters correctly for math ops errors Bart Schaefer
2024-02-22  8:34                     ` [PATCH] unmetafy Re: $var not expanded in ${x?$var} Roman Perepelitsa
2024-02-22 17:07                       ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240220070505.fd6jfbcdldieqv7u@chazelas.org \
    --to=stephane@chazelas.org \
    --cc=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).