Repository navigation
Description
From the documentation:
http://fishshell.com/docs/current/#expand-wildcard
If none of the wildcarded arguments sent to a command result in any matches, the command will not be executed. If this happens when using the shell interactively, a warning will also be printed.
It still gets executed after being deleted.
This used to work for me, it might be related to my fish version.
fizzfaldt@buk ~/fishtest> fish --version
fish, version 2.2.0
fizzfaldt@buk ~/fishtest> dpkg -l | grep fish
ii fish 2.2.0-1~trusty amd64 friendly interactive shell
Create a directory containing "foo" and "bar"
fizzfaldt@buk ~/fishtest> command /bin/ls -1 -l
total 0
-rw-rw-r-- 1 fizzfaldt fizzfaldt 0 Sep 16 00:38 bar
-rw-rw-r-- 1 fizzfaldt fizzfaldt 0 Sep 16 00:38 foo
If none of the wildcarded arguments sent to a command result in any matches, the command will not be executed.
This fails.. it expands the wildcards to zero arguments, but it still EXECUTES the command:
fizzfaldt@buk ~/fishtest> command /bin/ls -1 -l c*
No matches for wildcard “c*”.
fish: command /bin/ls -1 -l c*
^
total 0
-rw-rw-r-- 1 fizzfaldt fizzfaldt 0 Sep 16 00:38 bar
-rw-rw-r-- 1 fizzfaldt fizzfaldt 0 Sep 16 00:38 foo
fizzfaldt@buk ~/fishtest>
Note that if no matches are found for a specific wildcard, it will expand into zero arguments, i.e. to nothing.
This one works: If I have multiple wildcards, but at least one of them matches something, I get a warning, the non-matching ones become nothing, the matching one is expanded, and the command is executed:
fizzfaldt@buk ~/fishtest> command /bin/ls -1 -l b* c* d*
No matches for wildcard “c*”.
fish: command /bin/ls -1 -l b* c* d*
^
No matches for wildcard “d*”.
fish: command /bin/ls -1 -l b* c* d*
^
-rw-rw-r-- 1 fizzfaldt fizzfaldt 0 Sep 16 00:38 bar
fizzfaldt@buk ~/fishtest> command /bin/ls -1 -l c* b* d*
No matches for wildcard “c*”.
fish: command /bin/ls -1 -l c* b* d*
^
No matches for wildcard “d*”.
fish: command /bin/ls -1 -l c* b* d*
^
-rw-rw-r-- 1 fizzfaldt fizzfaldt 0 Sep 16 00:38 bar
Activity
zanchey commentedon Sep 16, 2015
See #1920, #1482.
fizzfaldt commentedon Sep 16, 2015
At the very least, assuming the change in behavior is intentional, the documentation needs to be updated.
For example, just deleting the line:
I do feel we have the worst of all worlds right now.
We don't pass globs to subcommands, so we often have to escape them, and we have no control over how it works (no options to switch behavior).
I liked getting errors when the globs failed, and would have preferred they always fail even if there were multiples. Is there no intention to have options then?
ridiculousfish commentedon Sep 16, 2015
Today's "
ls *.txtprints everything" behavior is horrible.faho commentedon Sep 16, 2015
Yes, it is. But what's the correct behavior? The previous "
ls *.txtfails, and you can't do anything to detect it or to suppress the error message" wasn't perfect either.For the
lscase, you clearly don't want to have globs expand to nothing, but forfor i in *orset foo *you probably want just that (and I believe we all agree that passing the bare "*" character is the worst possible solution).bgeron commentedon Sep 22, 2015
I think the best option is to fail by default (so converts from
shdon't hurt themselves), and add aemptyglobcommand mentioned in #1920 .+1.
ridiculousfish commentedon Sep 27, 2015
Another possibility is to make
*and**fail by default, but introduce new globs*?and**?that expand to empty instead of failing. I think I like that a bit better because it attaches to the glob instead of the command - what do others think?faho commentedon Sep 27, 2015
First of all, we already have a "?" for globs. I presume you mean to ditch that and replace it with this?
Otherwise, the idea of attaching it to globs sounds nice. I'm not sure if a more extensible syntax would make sense - zsh has glob qualifiers, which are very powerful but utterly unreadable. Unfortunately, I can't come up with a nice syntax.
ridiculousfish commentedon Sep 27, 2015
?matches any one character, while*matches zero or more characters. So*?has no real utility: any character matched by the?could also be matched by the*. I propose grabbing this currently useless syntax to make a new glob*?that does the emptyglob thing.Ok, that's not really true:
*matches the empty string, while*?only matches one-or-more characters. But one-or-more would still be available as?*after this change.ridiculousfish commentedon Sep 27, 2015
I guess another, more conservative option is to make
emptygloba command instead of a command modifier. So instead ofemptyglob ls *.txtit would bels (emptyglob *.txt).faho commentedon Sep 27, 2015
And a one character glob that should come up empty instead of fail? "??" would either match any two characters or fail, or match any one character or come up empty - it's ambiguous.
The issue I have with that is that I'd have to use it almost always.
The best I could come up with is something like
*[empty]- the brackets are already special for other substitutions and are currently not used for globs, so it makes sense to use them for something. It's also extensible -?[empty,file]or*[0..5], but I'm not sure if it's fishy enough.Well, that or fail and make certain commands (
setandforcome to mind) special.anordal commentedon Sep 27, 2015
regex > emptyglob
anordal commentedon Sep 27, 2015
I like how
?in*?and**?borrows syntax from regex. There it means, match once or nothing.ridiculousfish commentedon Sep 27, 2015
@faho can you elaborate on how you'd have to use it almost always?
faho commentedon Sep 27, 2015
I wrote a rather long and confused comment here before I recognized that I probably forgot that making globs fail also means not setting $status to 0. Currently globs behave a little confusing here -
setandforfail with status 124, everything else (?) gets an empty argument and may therefore return 0 - meaning you can't detect if a glob with, say,lsfailed.Frankly, all I'd need in that regard is that failing globs set status to non-zero (so that a simple
orcan work if you don't care why it failed) and a way to detect that the glob failed, not the command itself (a $globstatus variable?).So: Disregard, me thinkings ungood.
35 remaining items
bgeron commentedon Feb 19, 2016
I think ridiculousfish meant 'rm -f', which is common in Makefiles. Make
has nullglob behaviour if I'm not mistaken.
Cheers, Bram
On Fri, 19 Feb 2016, at 05:42 PM, anordal wrote:
Links:
anordal commentedon Feb 19, 2016
Good point about
rm -f! I'll count that as example number 1.If you mean targets in Makefiles, make picks the first target in the file if you don't specify any, so no nullglob behaviour wrt targets. But the
wildcardfunction in Make has nullglob behaviour!bgeron commentedon Feb 19, 2016
No, I meant rules.
On Fri, 19 Feb 2016, at 06:10 PM, anordal wrote:
Links:
ridiculousfish commentedon Feb 19, 2016
Yes, I should have typed
rm -f, thanksfaho commentedon Feb 19, 2016
Specifically, for
rm -f, it's often okay if one of the globs matches, and if none matches it might still count as a success.jplews commentedon Mar 3, 2016
This behaviour got me with
cpwhere a source dir ended up empty andcpcomplained about not having a destination, in a situation with multiple sources that seems potentially dangerous,countseems to be the thing so all is well now.IMO makes sense to have
glob --nulland additional syntax for interactive efficiency, and re-purposing?and adding??, although*looks more like the symbol nullglob should have, with?for failblob.Command substitution seems to cover everything, and would make more sense to a beginner. Having deliberately not used [ ] for my entire life I like the approach Fish is taking, and people should be pushed to using bash sub-processes like I often see with perl (even though bash has string stuff).
I also think that the documentation is incorrect still, and perhaps it would be worth mentioning
countthere too.faho commentedon Mar 3, 2016
Count is mentioned in the documentation, unless you mean the ones hosted at fishshell.com, which are the ones from the last release.
faho commentedon May 19, 2016
There's not been new discussion in a while and I've not seen a huge need for syntactic sugar in practice (
setworks just fine), so I'm closing this for now. Maybe it'll come up again later.Quote case globs
🐛 Quote file glob when compressing PNGs