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;








7















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?










share|improve this question






























    7















    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?










    share|improve this question


























      7












      7








      7








      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?










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      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




















          1 Answer
          1






          active

          oldest

          votes


















          10














          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~^bar or ^(^foo|^bar)

          Some only found in zsh:




          • <1-23> (range of decimal numbers)

          • pattern~except


          • pattern(glob-qualifier) (the killer feature of zsh globs)


          • (pattern/)# (any level of subdirectories matching the pattern; 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)

          • ...





          share|improve this answer



























            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
            );



            );













            draft saved

            draft discarded


















            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









            10














            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~^bar or ^(^foo|^bar)

            Some only found in zsh:




            • <1-23> (range of decimal numbers)

            • pattern~except


            • pattern(glob-qualifier) (the killer feature of zsh globs)


            • (pattern/)# (any level of subdirectories matching the pattern; 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)

            • ...





            share|improve this answer





























              10














              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~^bar or ^(^foo|^bar)

              Some only found in zsh:




              • <1-23> (range of decimal numbers)

              • pattern~except


              • pattern(glob-qualifier) (the killer feature of zsh globs)


              • (pattern/)# (any level of subdirectories matching the pattern; 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)

              • ...





              share|improve this answer



























                10












                10








                10







                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~^bar or ^(^foo|^bar)

                Some only found in zsh:




                • <1-23> (range of decimal numbers)

                • pattern~except


                • pattern(glob-qualifier) (the killer feature of zsh globs)


                • (pattern/)# (any level of subdirectories matching the pattern; 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)

                • ...





                share|improve this answer















                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~^bar or ^(^foo|^bar)

                Some only found in zsh:




                • <1-23> (range of decimal numbers)

                • pattern~except


                • pattern(glob-qualifier) (the killer feature of zsh globs)


                • (pattern/)# (any level of subdirectories matching the pattern; 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)

                • ...






                share|improve this answer














                share|improve this answer



                share|improve this answer








                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



























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

                    Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

                    Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림