From: "Andreas Kähäri" <andreas.kahari@abc.se>
To: "Lawrence Velázquez" <larryv@zsh.org>
Cc: zsh-users@zsh.org
Subject: Re: color codes to eval
Date: Wed, 10 Apr 2024 21:05:59 +0200 [thread overview]
Message-ID: <ZhbjF4CfK2PcPROp@eeyore.local> (raw)
In-Reply-To: <0338833d-1414-4c34-8bea-793f45d4115a@app.fastmail.com>
On Wed, Apr 10, 2024 at 02:39:45PM -0400, Lawrence Velázquez wrote:
> On Wed, Apr 10, 2024, at 12:46 PM, Ray Andrews wrote:
> > var="${red}howdy${nrm}" # '$(red}' is just a color code, no problem there.
> > print -l $var
> > eval "print -l $var"
> >
> > ... shows:
> >
> > howdy
> > (eval):1: bad pattern: ^[[31
> >
> > ... Is there a way to feed color codes to eval?
>
> The issue is not "color codes" per se. It's the fact that (assuming
> ECMA-48 sequences) you're assembling and evaluating a command that
> contains a word with an unquoted, unpaired "[" character, which zsh
> deems to be an invalid glob (by default). It's no different from:
>
> % print a[b
> zsh: bad pattern: a[b
>
>
> > Seems to me I remember
> > that there's some ${(?) var} ... some flag in there that does it.
>
> There are a number of possible solutions.
>
> # Avoid the pointless eval in the first place.
> print -l $var
>
> # Delay all expansions.
> eval 'print -l $var'
>
> # Delay the problematic expansion only.
> eval "print -l \$var"
>
> # Delay learning how quoting actually works.
> eval "print -l ${(q)var}"
>
> # Leave invalid patterns in the command.
> unsetopt BAD_PATTERN
> eval "print -l $var"
>
>
> --
> vq
They could also use print with -P and start using the prompt escape
%F{red}, but that's bypassing the issue rather than handling the
original string.
--
Andreas (Kusalananda) Kähäri
Uppsala, Sweden
.
next prev parent reply other threads:[~2024-04-10 19:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-10 16:46 Ray Andrews
2024-04-10 18:39 ` Lawrence Velázquez
2024-04-10 19:05 ` Andreas Kähäri [this message]
2024-04-10 19:17 ` Ray Andrews
2024-04-10 19:12 ` Ray Andrews
2024-04-11 0:01 ` Lawrence Velázquez
2024-04-11 0:15 ` Ray Andrews
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=ZhbjF4CfK2PcPROp@eeyore.local \
--to=andreas.kahari@abc.se \
--cc=larryv@zsh.org \
--cc=zsh-users@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).