From: "Lawrence Velázquez" <larryv@zsh.org>
To: "Ray Andrews" <rayandrews@eastlink.ca>
Cc: zsh-users@zsh.org
Subject: Re: trivial question
Date: Sun, 04 Dec 2022 21:52:06 -0500 [thread overview]
Message-ID: <63ae2364-1bba-405d-a1e6-4813df512340@app.fastmail.com> (raw)
In-Reply-To: <9d81fc7d-aa60-9b6a-47df-6fc677b933f9@eastlink.ca>
On Sun, Dec 4, 2022, at 9:05 PM, Ray Andrews wrote:
> Running this:
>
> var=( "now is" "the time" "for all good" "men to" )
>
> echo var[2] ain\'t nothing
> echo var2] ain\'t nothing
> echo "var[2]"
> echo $var[2]
>
> ... I get this:
>
> 4 /aWorking/Zsh/Source/Wk 0 $ . test1
> ain't nothing
> var2] ain't nothing
> var[2]
> the time
>
>
> ... It hardly matters but I'm curious that 'var[2]' without the dollar
> sign evaluates to nothing at all.
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.
% cat foo.zsh
var=('now is' 'the time' 'for all good' 'men to')
printf '<%s>' var[2] ain\'t nothing
echo
% : >var2
% zsh foo.zsh
<var2><ain't><nothing>
If no file or directory matches, zsh generates an error by default.
% rm var2
% zsh foo.zsh
foo.zsh:3: no matches found: var[2]
If NULL_GLOB is enabled (which you presumably have done), the failed
glob expands to nothing instead.
% zsh -o NULL_GLOB foo.zsh
<ain't><nothing>
> I have zero need for it to do
> otherwise still I'm mildly expecting it to just end up as a plain string
This happens if NOMATCH is disabled.
% zsh +o NOMATCH foo.zsh
<var[2]><ain't><nothing>
It is also the default behavior for failed globs in other shells.
> the same way 'var2]' does.
The latter is not a valid glob, so zsh does not attempt to generate
filenames with it. It is just passed as a literal argument.
> Seems strange that it evaporates entirely.
This is all explained in the manual.
https://zsh.sourceforge.io/Doc/Release/Expansion.html#Filename-Generation
--
vq
next prev parent reply other threads:[~2022-12-05 2:53 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 [this message]
2022-12-05 5:20 ` Ray Andrews
2022-12-05 6:40 ` Lawrence Velázquez
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=63ae2364-1bba-405d-a1e6-4813df512340@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).