zsh-users
 help / color / mirror / code / Atom feed
From: "Lawrence Velázquez" <larryv@zsh.org>
To: "Ray Andrews" <rayandrews@eastlink.ca>
Cc: zsh-users@zsh.org
Subject: Re: trivial question
Date: Mon, 05 Dec 2022 01:40:37 -0500	[thread overview]
Message-ID: <8fc6bf49-3463-4432-b706-15b49d19a9b5@app.fastmail.com> (raw)
In-Reply-To: <ca5c08fc-d81a-5e2c-d8ac-d4c60926ecaf@eastlink.ca>

On Mon, Dec 5, 2022, at 12:20 AM, Ray Andrews wrote:
> On 2022-12-04 18:52, Lawrence Velázquez wrote:
>> In this context, "var[2]" is recognized as a valid glob, and zsh
>> attempts to generate filenames with it.  If a file or directory
>> matches, its name is inserted as usual.
> I see.  A file glob would be the last thing I'd be expecting, I'm 
> expecting it to be a nothing but a string.

It's common enough to forget (or not know) that globs support bracket
expressions.  Most unquoted uses like yours are incorrect and can
produce unexpected results if they actually match anything (as
unlikely as that might be).

	% var=(a b c)
	% var1=hello
	% unset var[1]
	zsh: no matches found: var[1]
	% typeset -p var var1
	typeset -a var=( a b c )
	typeset var1=hello
	% : >var1
	% unset var[1]       
	% typeset -p var var1
	typeset: no such variable: var1
	typeset -a var=( a b c )
	% unset 'var[1]'     
	% typeset -p var var1
	typeset: no such variable: var1
	typeset -a var=( '' b c )

See also: https://mywiki.wooledge.org/BashPitfalls#unset_a.5B0.5D


>> % zsh +o NOMATCH foo.zsh
>> 	<var[2]><ain't><nothing>
>>
> That works.  First experiments trying '(un)setopt NOMATCH' aren't 
> working but now that I know what to chew on I'll bag it.

That was a demonstration of behavior, not a suggestion to disable
NOMATCH.  Leaving unmatched globs intact is rarely what you want.

	% setopt NOMATCH NO_NULL_GLOB
	% touch nonexistent*
	zsh: no matches found: nonexistent*
	% ls
	% unsetopt NOMATCH
	% touch nonexistent*
	% ls
	nonexistent*

You really need to get out of the habit of enabling/disabling options
that you don't understand just because one of us explains how they
change some behavior or other.  You did the same thing with ERR_EXIT
in users/28432, and it was equally misguided.

The correct remedy here, as usual, is to quote properly, not fiddle
with options.


-- 
vq


  reply	other threads:[~2022-12-05  6:42 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-05  2:05 Ray Andrews
2022-12-05  2:52 ` Lawrence Velázquez
2022-12-05  5:20   ` Ray Andrews
2022-12-05  6:40     ` Lawrence Velázquez [this message]
2022-12-05 14:11       ` Ray Andrews
2022-12-06  2:12         ` Lawrence Velázquez
2022-12-06  2:29           ` Ray Andrews
2022-12-06  4:29             ` Bart Schaefer
2022-12-06  6:08               ` Lawrence Velázquez
2022-12-06 10:18               ` Roman Perepelitsa
2022-12-06 11:21                 ` Peter Stephenson
2022-12-06 15:28               ` Ray Andrews
2022-12-06 18:53                 ` Bart Schaefer
2022-12-07  0:02                 ` Lawrence Velázquez

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=8fc6bf49-3463-4432-b706-15b49d19a9b5@app.fastmail.com \
    --to=larryv@zsh.org \
    --cc=rayandrews@eastlink.ca \
    --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).