zsh-users
 help / color / mirror / code / Atom feed
From: "Lawrence Velázquez" <larryv@zsh.org>
To: zsh-users@zsh.org
Subject: Re: color codes to eval
Date: Wed, 10 Apr 2024 20:01:37 -0400	[thread overview]
Message-ID: <02e80e14-471d-4084-9ba1-148aedd70443@app.fastmail.com> (raw)
In-Reply-To: <47548b8e-a5e6-4fbb-8b57-4f3055f22c91@eastlink.ca>

On Wed, Apr 10, 2024, at 3:12 PM, Ray Andrews wrote:
> On 2024-04-10 11:39, Lawrence Velázquez wrote:
>> 	# Delay all expansions.
>> 	eval 'print -l $var'
> Works!  And I believe I understand it.  '$var' *will* expand even though it doesn't look like it, because eval takes a second crack at the line after the single quotes are removed, yes?

That's right.  And since you're not using $~var or GLOB_SUBST, the
result of that delayed expansion will be used literally instead of
as a pattern for filename generation.


>> 	# Delay learning how quoting actually works.
>> 	eval "print -l ${(q)var}"
> I'll play with that further, that's the thing I was trying to remember.  First efforts are not working, but I do recall that '(q)' ended up giving me trouble down the line and was best avoided.

If you can avoid it, you might as well.  (Especially if you don't
have a clear idea of what it does.)


>> 	# Leave invalid patterns in the command.
>> 	unsetopt BAD_PATTERN
>> 	eval "print -l $var"
> Looks dangerous!  Looks like bad practice.

It's usually not what you want, since it may let typos and other
mistakes go by quietly.  It's generally easy enough to handle
troublesome non-patterns by quoting them or using them through
variables.

NO_BAD_PATTERN does align more closely with POSIX and other shells
and is the behavior used in sh/ksh emulation.

	% script='echo a[b'
	% bash -c $script
	a[b
	% dash -c $script
	a[b
	% ksh -c $script
	a[b
	% mksh -c $script
	a[b
	% yash -c $script
	a[b
	% zsh -c $script
	zsh:1: bad pattern: a[b
	% zsh +o BAD_PATTERN -c $script
	a[b


-- 
vq


  reply	other threads:[~2024-04-11  0:03 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
2024-04-10 19:17     ` Ray Andrews
2024-04-10 19:12   ` Ray Andrews
2024-04-11  0:01     ` Lawrence Velázquez [this message]
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=02e80e14-471d-4084-9ba1-148aedd70443@app.fastmail.com \
    --to=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).