Why can't I use !(single pattern) in zsh even after I turn on kshglob?Why does this command to copy files in a for loop work in bash but not in zsh?How to deal with filenames containing a single quote inside a zsh completion function?Why isn't zsh autocomplete using history behaving consistently from login to login?Why can't I define a readonly variable named path in zsh?Bash script copy file to user's (wildcard) home dirUse colon as filename separator in zsh tab completionWhy does a failed filename generation make zsh stop processing a script?Can't load antigen in zsh - my source command always gets an extra “/bin” appendedWhy does zsh list my prompt incorrectly on OS X?SHELL environment variable still points to zsh after using bash
Can the word "desk" be used as a verb?
Is there a strong legal guarantee that the U.S. can give to another country that it won't attack them?
Do injective, yet not bijective, functions have an inverse?
Intern not wearing safety equipment; how could I have handled this differently?
How to convert diagonal matrix to rectangular matrix
Users forgetting to regenerate PDF before sending it
Password Hashing Security Using Scrypt & Argon2
What was the profession 芸者 (female entertainer) called in Russia?
What exactly is a "murder hobo"?
Publishing papers seem natural to many, while I find it really hard to think novel stuff to pursue till publication. How to cope up with this?
Why different specifications for telescopes and binoculars?
Is it okay to use open source code to do an interview task?
When do flights get cancelled due to fog?
Why AI became applicable only after Nvidia's chips were available?
My previous employer committed a severe violation of the law and is also being sued by me. How do I explain the situation to future employers?
Is it ok for parents to kiss and romance with each other while their 2- to 8-year-old child watches?
What are the effects of abstaining from eating a certain flavor?
Conditions for Roots of a quadratic equation at infinity
What happens to unproductive professors?
What do you call a situation where you have choices but no good choice?
Would a Nikon FG 20 film SLR camera take pictures without batteries?
How many Jimmys can fit?
I make billions (#6)
Any unique interactions, with an Altmer Dragonborn?
Why can't I use !(single pattern) in zsh even after I turn on kshglob?
Why does this command to copy files in a for loop work in bash but not in zsh?How to deal with filenames containing a single quote inside a zsh completion function?Why isn't zsh autocomplete using history behaving consistently from login to login?Why can't I define a readonly variable named path in zsh?Bash script copy file to user's (wildcard) home dirUse colon as filename separator in zsh tab completionWhy does a failed filename generation make zsh stop processing a script?Can't load antigen in zsh - my source command always gets an extra “/bin” appendedWhy does zsh list my prompt incorrectly on OS X?SHELL environment variable still points to zsh after using bash
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
This works in bash:
touch a b c
echo !(a)
If I execute above script in zsh (with kshglob on), it complains:
zsh: number expected
If I add | after a, it works:
echo !(a|)
Why?
zsh wildcards
add a comment |
This works in bash:
touch a b c
echo !(a)
If I execute above script in zsh (with kshglob on), it complains:
zsh: number expected
If I add | after a, it works:
echo !(a|)
Why?
zsh wildcards
add a comment |
This works in bash:
touch a b c
echo !(a)
If I execute above script in zsh (with kshglob on), it complains:
zsh: number expected
If I add | after a, it works:
echo !(a|)
Why?
zsh wildcards
This works in bash:
touch a b c
echo !(a)
If I execute above script in zsh (with kshglob on), it complains:
zsh: number expected
If I add | after a, it works:
echo !(a|)
Why?
zsh wildcards
zsh wildcards
edited Jul 1 at 10:19
Jeff Schaller♦
47.5k11 gold badges69 silver badges154 bronze badges
47.5k11 gold badges69 silver badges154 bronze badges
asked Jun 30 at 6:01
dedowsdidedowsdi
8652 silver badges9 bronze badges
8652 silver badges9 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Because in this case, it conflicts with bare glob qualifiers since it's at the end of the pattern. *(a1) is taken as the files last accessed in the last day. (a1) is treated as a glob qualifier. So in your !(a) case, zsh complains about the missing number of days after the a glob qualifier (here applied to the file called !).
In zsh globs, (...) grouping is mostly used for the (foo|bar) alternation, so adding a | is a documented way to make sure a trailing (...) is not treated as a glob qualifier.
Another documented alternative is to double the parenthesis (!((a))) or you could add an empty glob qualifier (like !(a)(-)).
To completely remove that ambiguity, one can turn off the bare_glob_qual option (set +o bareglobqual), after which glob qualifiers have to be written with the extendedglob (#q...) syntax (*(#qa1) here).
The kshglob option (added in 1998, roughly the same time bash added its extglob though bash didn't have any extended glob before that) is mostly there for the ksh emulation mode (emulate ksh), for zsh to be able to run ksh scripts, where kshglob is enabled and bareglobqual is disabled. When it was first introduced, after enabling kshglob, you'd need to specify glob qualifiers as -(...) to avoid that kind of conflict but that caused too much confusion and conflicted with the @-(...) syntax of ksh93, the (#q...) and bareglobqual options were introduced later.
zsh users generally prefer zsh's own extended glob (set -o extendedglob) operators which are easier to type (for most) and more powerful (than the ksh88 ones enabled with kshglob also found in bash -O extglob).
For example, !(foo) would be written ^foo. The !(foo|)bar equivalent would however be longer like (^(foo|))bar.
Other ksh88 -> zsh translations:
*(x)->x#+(x)->x##@(x|y)->x|y?(x)->(x|)
Some ksh93 -> zsh translations:
~(i:x)->(#i)x(case insensitive)~(N)x->x(N)(nullglob, originated in zsh)1,5(x)->x(#c1,5)@(foo&bar)->foo~^baror^(^foo|^bar)
Some only found in zsh:
<1-23>(range of decimal numbers)pattern~exceptpattern(glob-qualifier)(the killer feature of zsh globs)(pattern/)#(any level of subdirectories matching thepattern; the**/simplified version of(*/)#was also added to ksh93 and bash recently)***/*(recursive globbing following symlinks).(#a1)foobar(approximate matching, allowing some errors, here 1)- ...
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f527704%2fwhy-cant-i-use-single-pattern-in-zsh-even-after-i-turn-on-kshglob%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Because in this case, it conflicts with bare glob qualifiers since it's at the end of the pattern. *(a1) is taken as the files last accessed in the last day. (a1) is treated as a glob qualifier. So in your !(a) case, zsh complains about the missing number of days after the a glob qualifier (here applied to the file called !).
In zsh globs, (...) grouping is mostly used for the (foo|bar) alternation, so adding a | is a documented way to make sure a trailing (...) is not treated as a glob qualifier.
Another documented alternative is to double the parenthesis (!((a))) or you could add an empty glob qualifier (like !(a)(-)).
To completely remove that ambiguity, one can turn off the bare_glob_qual option (set +o bareglobqual), after which glob qualifiers have to be written with the extendedglob (#q...) syntax (*(#qa1) here).
The kshglob option (added in 1998, roughly the same time bash added its extglob though bash didn't have any extended glob before that) is mostly there for the ksh emulation mode (emulate ksh), for zsh to be able to run ksh scripts, where kshglob is enabled and bareglobqual is disabled. When it was first introduced, after enabling kshglob, you'd need to specify glob qualifiers as -(...) to avoid that kind of conflict but that caused too much confusion and conflicted with the @-(...) syntax of ksh93, the (#q...) and bareglobqual options were introduced later.
zsh users generally prefer zsh's own extended glob (set -o extendedglob) operators which are easier to type (for most) and more powerful (than the ksh88 ones enabled with kshglob also found in bash -O extglob).
For example, !(foo) would be written ^foo. The !(foo|)bar equivalent would however be longer like (^(foo|))bar.
Other ksh88 -> zsh translations:
*(x)->x#+(x)->x##@(x|y)->x|y?(x)->(x|)
Some ksh93 -> zsh translations:
~(i:x)->(#i)x(case insensitive)~(N)x->x(N)(nullglob, originated in zsh)1,5(x)->x(#c1,5)@(foo&bar)->foo~^baror^(^foo|^bar)
Some only found in zsh:
<1-23>(range of decimal numbers)pattern~exceptpattern(glob-qualifier)(the killer feature of zsh globs)(pattern/)#(any level of subdirectories matching thepattern; the**/simplified version of(*/)#was also added to ksh93 and bash recently)***/*(recursive globbing following symlinks).(#a1)foobar(approximate matching, allowing some errors, here 1)- ...
add a comment |
Because in this case, it conflicts with bare glob qualifiers since it's at the end of the pattern. *(a1) is taken as the files last accessed in the last day. (a1) is treated as a glob qualifier. So in your !(a) case, zsh complains about the missing number of days after the a glob qualifier (here applied to the file called !).
In zsh globs, (...) grouping is mostly used for the (foo|bar) alternation, so adding a | is a documented way to make sure a trailing (...) is not treated as a glob qualifier.
Another documented alternative is to double the parenthesis (!((a))) or you could add an empty glob qualifier (like !(a)(-)).
To completely remove that ambiguity, one can turn off the bare_glob_qual option (set +o bareglobqual), after which glob qualifiers have to be written with the extendedglob (#q...) syntax (*(#qa1) here).
The kshglob option (added in 1998, roughly the same time bash added its extglob though bash didn't have any extended glob before that) is mostly there for the ksh emulation mode (emulate ksh), for zsh to be able to run ksh scripts, where kshglob is enabled and bareglobqual is disabled. When it was first introduced, after enabling kshglob, you'd need to specify glob qualifiers as -(...) to avoid that kind of conflict but that caused too much confusion and conflicted with the @-(...) syntax of ksh93, the (#q...) and bareglobqual options were introduced later.
zsh users generally prefer zsh's own extended glob (set -o extendedglob) operators which are easier to type (for most) and more powerful (than the ksh88 ones enabled with kshglob also found in bash -O extglob).
For example, !(foo) would be written ^foo. The !(foo|)bar equivalent would however be longer like (^(foo|))bar.
Other ksh88 -> zsh translations:
*(x)->x#+(x)->x##@(x|y)->x|y?(x)->(x|)
Some ksh93 -> zsh translations:
~(i:x)->(#i)x(case insensitive)~(N)x->x(N)(nullglob, originated in zsh)1,5(x)->x(#c1,5)@(foo&bar)->foo~^baror^(^foo|^bar)
Some only found in zsh:
<1-23>(range of decimal numbers)pattern~exceptpattern(glob-qualifier)(the killer feature of zsh globs)(pattern/)#(any level of subdirectories matching thepattern; the**/simplified version of(*/)#was also added to ksh93 and bash recently)***/*(recursive globbing following symlinks).(#a1)foobar(approximate matching, allowing some errors, here 1)- ...
add a comment |
Because in this case, it conflicts with bare glob qualifiers since it's at the end of the pattern. *(a1) is taken as the files last accessed in the last day. (a1) is treated as a glob qualifier. So in your !(a) case, zsh complains about the missing number of days after the a glob qualifier (here applied to the file called !).
In zsh globs, (...) grouping is mostly used for the (foo|bar) alternation, so adding a | is a documented way to make sure a trailing (...) is not treated as a glob qualifier.
Another documented alternative is to double the parenthesis (!((a))) or you could add an empty glob qualifier (like !(a)(-)).
To completely remove that ambiguity, one can turn off the bare_glob_qual option (set +o bareglobqual), after which glob qualifiers have to be written with the extendedglob (#q...) syntax (*(#qa1) here).
The kshglob option (added in 1998, roughly the same time bash added its extglob though bash didn't have any extended glob before that) is mostly there for the ksh emulation mode (emulate ksh), for zsh to be able to run ksh scripts, where kshglob is enabled and bareglobqual is disabled. When it was first introduced, after enabling kshglob, you'd need to specify glob qualifiers as -(...) to avoid that kind of conflict but that caused too much confusion and conflicted with the @-(...) syntax of ksh93, the (#q...) and bareglobqual options were introduced later.
zsh users generally prefer zsh's own extended glob (set -o extendedglob) operators which are easier to type (for most) and more powerful (than the ksh88 ones enabled with kshglob also found in bash -O extglob).
For example, !(foo) would be written ^foo. The !(foo|)bar equivalent would however be longer like (^(foo|))bar.
Other ksh88 -> zsh translations:
*(x)->x#+(x)->x##@(x|y)->x|y?(x)->(x|)
Some ksh93 -> zsh translations:
~(i:x)->(#i)x(case insensitive)~(N)x->x(N)(nullglob, originated in zsh)1,5(x)->x(#c1,5)@(foo&bar)->foo~^baror^(^foo|^bar)
Some only found in zsh:
<1-23>(range of decimal numbers)pattern~exceptpattern(glob-qualifier)(the killer feature of zsh globs)(pattern/)#(any level of subdirectories matching thepattern; the**/simplified version of(*/)#was also added to ksh93 and bash recently)***/*(recursive globbing following symlinks).(#a1)foobar(approximate matching, allowing some errors, here 1)- ...
Because in this case, it conflicts with bare glob qualifiers since it's at the end of the pattern. *(a1) is taken as the files last accessed in the last day. (a1) is treated as a glob qualifier. So in your !(a) case, zsh complains about the missing number of days after the a glob qualifier (here applied to the file called !).
In zsh globs, (...) grouping is mostly used for the (foo|bar) alternation, so adding a | is a documented way to make sure a trailing (...) is not treated as a glob qualifier.
Another documented alternative is to double the parenthesis (!((a))) or you could add an empty glob qualifier (like !(a)(-)).
To completely remove that ambiguity, one can turn off the bare_glob_qual option (set +o bareglobqual), after which glob qualifiers have to be written with the extendedglob (#q...) syntax (*(#qa1) here).
The kshglob option (added in 1998, roughly the same time bash added its extglob though bash didn't have any extended glob before that) is mostly there for the ksh emulation mode (emulate ksh), for zsh to be able to run ksh scripts, where kshglob is enabled and bareglobqual is disabled. When it was first introduced, after enabling kshglob, you'd need to specify glob qualifiers as -(...) to avoid that kind of conflict but that caused too much confusion and conflicted with the @-(...) syntax of ksh93, the (#q...) and bareglobqual options were introduced later.
zsh users generally prefer zsh's own extended glob (set -o extendedglob) operators which are easier to type (for most) and more powerful (than the ksh88 ones enabled with kshglob also found in bash -O extglob).
For example, !(foo) would be written ^foo. The !(foo|)bar equivalent would however be longer like (^(foo|))bar.
Other ksh88 -> zsh translations:
*(x)->x#+(x)->x##@(x|y)->x|y?(x)->(x|)
Some ksh93 -> zsh translations:
~(i:x)->(#i)x(case insensitive)~(N)x->x(N)(nullglob, originated in zsh)1,5(x)->x(#c1,5)@(foo&bar)->foo~^baror^(^foo|^bar)
Some only found in zsh:
<1-23>(range of decimal numbers)pattern~exceptpattern(glob-qualifier)(the killer feature of zsh globs)(pattern/)#(any level of subdirectories matching thepattern; the**/simplified version of(*/)#was also added to ksh93 and bash recently)***/*(recursive globbing following symlinks).(#a1)foobar(approximate matching, allowing some errors, here 1)- ...
edited Jun 30 at 11:48
answered Jun 30 at 7:03
Stéphane ChazelasStéphane Chazelas
325k57 gold badges628 silver badges997 bronze badges
325k57 gold badges628 silver badges997 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f527704%2fwhy-cant-i-use-single-pattern-in-zsh-even-after-i-turn-on-kshglob%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown