From: Anthony Heading <anthony@ajrh.net>
To: zsh-users@zsh.org
Subject: NOMATCH errors
Date: Thu, 05 Jan 2017 22:35:21 -0500 [thread overview]
Message-ID: <1483673721.1546772.838942313.0683A864@webmail.messagingengine.com> (raw)
Hi,
I was dusting off an old script which, admittedly inelegantly, did
PYTHON==python 2>/dev/null
with NOMATCH set, which in the zsh 5 era seems to be a fatal error, i.e.
a script
echo hello
echo =hello =hello
echo "is there anybody in there?"
doesn't get past:
hello
hello:2: hello not found
Interestingly the docs perhaps arguably seem to imply differently:
Fatal errors found in non-interactive shells include:
[...]
o File generation failures where not caused by NO_MATCH or similar
options
So I was wondering the cleanest way to do this. `which python` is the
old-school
way, I guess, but the documentation isn't very reassuring about output
format
in case it happens to be an alias or a function or (heaven forfend)
python becomes
a shell builtin.
I played for a few minutes with a trivial patch at the end of this
email, which
aimed to make ==missing expand to an empty string. That to me seems a
helpful
behaviour, enables e.g. ${${:-==python}:-perl}, although it feels very
special
case syntax, maybe something as a variant or modifier on the :c
expansion would be
neater. But then if the idea is valid, maybe it sense to be able to
soft test tilde dir
expansion too; I'm not aware a nice way to look up single entries in
the hash tables, so maybe a general syntax for that could be better.
Any thoughts appreciated, especially if I'm missing a neat way to do
this.
Thanks
Anthony
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -623,13 +623,18 @@ char *
equalsubstr(char *str, int assign, int nomatch)
{
char *pp, *cnam, *cmdstr, *ret;
+ int nullmatch = str[0] == Equals;
for (pp = str; !isend2(*pp); pp++)
;
cmdstr = dupstrpfx(str, pp-str);
untokenize(cmdstr);
remnulargs(cmdstr);
+ if (nullmatch)
+ cmdstr++;
if (!(cnam = findcmd(cmdstr, 1, 0))) {
+ if (nullmatch)
+ return dupstring("");
if (nomatch)
zerr("%s not found", cmdstr);
return NULL;
next reply other threads:[~2017-01-06 3:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20170106034111epcas4p3f9c5c44d3d8318b096fbe5c3dc899439@epcas4p3.samsung.com>
2017-01-06 3:35 ` Anthony Heading [this message]
2017-01-06 11:49 ` Peter Stephenson
2017-01-06 16:05 ` Eric Cook
2017-01-07 2:37 ` Anthony Heading
2017-01-08 18:35 ` 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=1483673721.1546772.838942313.0683A864@webmail.messagingengine.com \
--to=anthony@ajrh.net \
--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).