What's Linux test -a command test for?












3















Please take a look at the following code,



snap=snapshot.file   
touch snapshot.file-1

$ [ -a $snap-1 ] && echo yes
yes


What does the test -a command tests for here?



I tried info coreutils 'test invocation' and searched for -a, but didn't find it in the file characteristic tests section, but rather in the connectives for test section.



Is such test -a command an undocumented one?



NB, My system is Ubuntu 13.10 and my man test says GNU coreutils 8.20 October 2012 TEST(1).










share|improve this question





























    3















    Please take a look at the following code,



    snap=snapshot.file   
    touch snapshot.file-1

    $ [ -a $snap-1 ] && echo yes
    yes


    What does the test -a command tests for here?



    I tried info coreutils 'test invocation' and searched for -a, but didn't find it in the file characteristic tests section, but rather in the connectives for test section.



    Is such test -a command an undocumented one?



    NB, My system is Ubuntu 13.10 and my man test says GNU coreutils 8.20 October 2012 TEST(1).










    share|improve this question



























      3












      3








      3








      Please take a look at the following code,



      snap=snapshot.file   
      touch snapshot.file-1

      $ [ -a $snap-1 ] && echo yes
      yes


      What does the test -a command tests for here?



      I tried info coreutils 'test invocation' and searched for -a, but didn't find it in the file characteristic tests section, but rather in the connectives for test section.



      Is such test -a command an undocumented one?



      NB, My system is Ubuntu 13.10 and my man test says GNU coreutils 8.20 October 2012 TEST(1).










      share|improve this question
















      Please take a look at the following code,



      snap=snapshot.file   
      touch snapshot.file-1

      $ [ -a $snap-1 ] && echo yes
      yes


      What does the test -a command tests for here?



      I tried info coreutils 'test invocation' and searched for -a, but didn't find it in the file characteristic tests section, but rather in the connectives for test section.



      Is such test -a command an undocumented one?



      NB, My system is Ubuntu 13.10 and my man test says GNU coreutils 8.20 October 2012 TEST(1).







      linux ubuntu command-line command-line-arguments






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 21 at 16:53







      xpt

















      asked Jun 17 '14 at 1:33









      xptxpt

      3,216145693




      3,216145693






















          3 Answers
          3






          active

          oldest

          votes


















          3














          I am not sure why the info page doesn't have it, but running help test in bash gives the answer:



          ...
          File operators:

          -a FILE True if file exists.
          ...


          So it is simply an "existence" test, no other permissions/attributes checked.






          share|improve this answer
























          • Perfect! Thanks. Strange, man test doesn't have that either. only help test does. Does that mean it is a bash specific file existence testing?

            – xpt
            Jun 17 '14 at 3:57








          • 1





            @xpt It would seem like that is the case, but for me /bin/test -a file worked also...So why it isn't in the manpage I have NO idea.

            – BenjiWiebe
            Jun 17 '14 at 12:13



















          3














          If you're running test or [ in bash, it's actually probably the built-in version, and not the coreutils version in /usr/bin:



          $ type test
          test is a shell builtin
          $ type [
          [ is a shell builtin


          That said, it does appear that the coreutils version implements both -a and -e, with exactly the same behavior. Maybe -a is not reflected in the manpage because it's not standard, so maybe it was added later and that person neglected to update the manpage accordingly. But I can't say I know the history behind why it was added (or even what the a is supposed to be short for).






          share|improve this answer































            1














            -a is the AND operator for combining conditions, so the following shows yes if both directories exist:




            [ -e /root -a -e /usr ] && echo yes




            The use of it with a single condition that defaults to an existance test seems like retained old behavior but I can't find it in old man pages.



            Reference (scroll down some after info coreutils 'test invocation'):




            16.3.6 Connectives for `test'



            The usual logical connectives.



            `! EXPR'
            True if EXPR is false.



            `EXPR1 -a EXPR2'
            True if both EXPR1 and EXPR2 are true.



            `EXPR1 -o EXPR2'
            True if either EXPR1 or EXPR2 is true.







            share|improve this answer





















            • 1





              If you look at the coreutils source, the a and e cases share the same code in the function that handles unary operators, so I don't think it's an accidental thing.

              – jjlin
              Jun 17 '14 at 17:33











            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2fsuperuser.com%2fquestions%2f769670%2fwhats-linux-test-a-command-test-for%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            I am not sure why the info page doesn't have it, but running help test in bash gives the answer:



            ...
            File operators:

            -a FILE True if file exists.
            ...


            So it is simply an "existence" test, no other permissions/attributes checked.






            share|improve this answer
























            • Perfect! Thanks. Strange, man test doesn't have that either. only help test does. Does that mean it is a bash specific file existence testing?

              – xpt
              Jun 17 '14 at 3:57








            • 1





              @xpt It would seem like that is the case, but for me /bin/test -a file worked also...So why it isn't in the manpage I have NO idea.

              – BenjiWiebe
              Jun 17 '14 at 12:13
















            3














            I am not sure why the info page doesn't have it, but running help test in bash gives the answer:



            ...
            File operators:

            -a FILE True if file exists.
            ...


            So it is simply an "existence" test, no other permissions/attributes checked.






            share|improve this answer
























            • Perfect! Thanks. Strange, man test doesn't have that either. only help test does. Does that mean it is a bash specific file existence testing?

              – xpt
              Jun 17 '14 at 3:57








            • 1





              @xpt It would seem like that is the case, but for me /bin/test -a file worked also...So why it isn't in the manpage I have NO idea.

              – BenjiWiebe
              Jun 17 '14 at 12:13














            3












            3








            3







            I am not sure why the info page doesn't have it, but running help test in bash gives the answer:



            ...
            File operators:

            -a FILE True if file exists.
            ...


            So it is simply an "existence" test, no other permissions/attributes checked.






            share|improve this answer













            I am not sure why the info page doesn't have it, but running help test in bash gives the answer:



            ...
            File operators:

            -a FILE True if file exists.
            ...


            So it is simply an "existence" test, no other permissions/attributes checked.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jun 17 '14 at 1:42









            BenjiWiebeBenjiWiebe

            6,74093558




            6,74093558













            • Perfect! Thanks. Strange, man test doesn't have that either. only help test does. Does that mean it is a bash specific file existence testing?

              – xpt
              Jun 17 '14 at 3:57








            • 1





              @xpt It would seem like that is the case, but for me /bin/test -a file worked also...So why it isn't in the manpage I have NO idea.

              – BenjiWiebe
              Jun 17 '14 at 12:13



















            • Perfect! Thanks. Strange, man test doesn't have that either. only help test does. Does that mean it is a bash specific file existence testing?

              – xpt
              Jun 17 '14 at 3:57








            • 1





              @xpt It would seem like that is the case, but for me /bin/test -a file worked also...So why it isn't in the manpage I have NO idea.

              – BenjiWiebe
              Jun 17 '14 at 12:13

















            Perfect! Thanks. Strange, man test doesn't have that either. only help test does. Does that mean it is a bash specific file existence testing?

            – xpt
            Jun 17 '14 at 3:57







            Perfect! Thanks. Strange, man test doesn't have that either. only help test does. Does that mean it is a bash specific file existence testing?

            – xpt
            Jun 17 '14 at 3:57






            1




            1





            @xpt It would seem like that is the case, but for me /bin/test -a file worked also...So why it isn't in the manpage I have NO idea.

            – BenjiWiebe
            Jun 17 '14 at 12:13





            @xpt It would seem like that is the case, but for me /bin/test -a file worked also...So why it isn't in the manpage I have NO idea.

            – BenjiWiebe
            Jun 17 '14 at 12:13













            3














            If you're running test or [ in bash, it's actually probably the built-in version, and not the coreutils version in /usr/bin:



            $ type test
            test is a shell builtin
            $ type [
            [ is a shell builtin


            That said, it does appear that the coreutils version implements both -a and -e, with exactly the same behavior. Maybe -a is not reflected in the manpage because it's not standard, so maybe it was added later and that person neglected to update the manpage accordingly. But I can't say I know the history behind why it was added (or even what the a is supposed to be short for).






            share|improve this answer




























              3














              If you're running test or [ in bash, it's actually probably the built-in version, and not the coreutils version in /usr/bin:



              $ type test
              test is a shell builtin
              $ type [
              [ is a shell builtin


              That said, it does appear that the coreutils version implements both -a and -e, with exactly the same behavior. Maybe -a is not reflected in the manpage because it's not standard, so maybe it was added later and that person neglected to update the manpage accordingly. But I can't say I know the history behind why it was added (or even what the a is supposed to be short for).






              share|improve this answer


























                3












                3








                3







                If you're running test or [ in bash, it's actually probably the built-in version, and not the coreutils version in /usr/bin:



                $ type test
                test is a shell builtin
                $ type [
                [ is a shell builtin


                That said, it does appear that the coreutils version implements both -a and -e, with exactly the same behavior. Maybe -a is not reflected in the manpage because it's not standard, so maybe it was added later and that person neglected to update the manpage accordingly. But I can't say I know the history behind why it was added (or even what the a is supposed to be short for).






                share|improve this answer













                If you're running test or [ in bash, it's actually probably the built-in version, and not the coreutils version in /usr/bin:



                $ type test
                test is a shell builtin
                $ type [
                [ is a shell builtin


                That said, it does appear that the coreutils version implements both -a and -e, with exactly the same behavior. Maybe -a is not reflected in the manpage because it's not standard, so maybe it was added later and that person neglected to update the manpage accordingly. But I can't say I know the history behind why it was added (or even what the a is supposed to be short for).







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jun 17 '14 at 5:17









                jjlinjjlin

                11.9k33842




                11.9k33842























                    1














                    -a is the AND operator for combining conditions, so the following shows yes if both directories exist:




                    [ -e /root -a -e /usr ] && echo yes




                    The use of it with a single condition that defaults to an existance test seems like retained old behavior but I can't find it in old man pages.



                    Reference (scroll down some after info coreutils 'test invocation'):




                    16.3.6 Connectives for `test'



                    The usual logical connectives.



                    `! EXPR'
                    True if EXPR is false.



                    `EXPR1 -a EXPR2'
                    True if both EXPR1 and EXPR2 are true.



                    `EXPR1 -o EXPR2'
                    True if either EXPR1 or EXPR2 is true.







                    share|improve this answer





















                    • 1





                      If you look at the coreutils source, the a and e cases share the same code in the function that handles unary operators, so I don't think it's an accidental thing.

                      – jjlin
                      Jun 17 '14 at 17:33
















                    1














                    -a is the AND operator for combining conditions, so the following shows yes if both directories exist:




                    [ -e /root -a -e /usr ] && echo yes




                    The use of it with a single condition that defaults to an existance test seems like retained old behavior but I can't find it in old man pages.



                    Reference (scroll down some after info coreutils 'test invocation'):




                    16.3.6 Connectives for `test'



                    The usual logical connectives.



                    `! EXPR'
                    True if EXPR is false.



                    `EXPR1 -a EXPR2'
                    True if both EXPR1 and EXPR2 are true.



                    `EXPR1 -o EXPR2'
                    True if either EXPR1 or EXPR2 is true.







                    share|improve this answer





















                    • 1





                      If you look at the coreutils source, the a and e cases share the same code in the function that handles unary operators, so I don't think it's an accidental thing.

                      – jjlin
                      Jun 17 '14 at 17:33














                    1












                    1








                    1







                    -a is the AND operator for combining conditions, so the following shows yes if both directories exist:




                    [ -e /root -a -e /usr ] && echo yes




                    The use of it with a single condition that defaults to an existance test seems like retained old behavior but I can't find it in old man pages.



                    Reference (scroll down some after info coreutils 'test invocation'):




                    16.3.6 Connectives for `test'



                    The usual logical connectives.



                    `! EXPR'
                    True if EXPR is false.



                    `EXPR1 -a EXPR2'
                    True if both EXPR1 and EXPR2 are true.



                    `EXPR1 -o EXPR2'
                    True if either EXPR1 or EXPR2 is true.







                    share|improve this answer















                    -a is the AND operator for combining conditions, so the following shows yes if both directories exist:




                    [ -e /root -a -e /usr ] && echo yes




                    The use of it with a single condition that defaults to an existance test seems like retained old behavior but I can't find it in old man pages.



                    Reference (scroll down some after info coreutils 'test invocation'):




                    16.3.6 Connectives for `test'



                    The usual logical connectives.



                    `! EXPR'
                    True if EXPR is false.



                    `EXPR1 -a EXPR2'
                    True if both EXPR1 and EXPR2 are true.



                    `EXPR1 -o EXPR2'
                    True if either EXPR1 or EXPR2 is true.








                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Dec 24 '17 at 14:56

























                    answered Jun 17 '14 at 13:46









                    BrianBrian

                    8,2511833




                    8,2511833








                    • 1





                      If you look at the coreutils source, the a and e cases share the same code in the function that handles unary operators, so I don't think it's an accidental thing.

                      – jjlin
                      Jun 17 '14 at 17:33














                    • 1





                      If you look at the coreutils source, the a and e cases share the same code in the function that handles unary operators, so I don't think it's an accidental thing.

                      – jjlin
                      Jun 17 '14 at 17:33








                    1




                    1





                    If you look at the coreutils source, the a and e cases share the same code in the function that handles unary operators, so I don't think it's an accidental thing.

                    – jjlin
                    Jun 17 '14 at 17:33





                    If you look at the coreutils source, the a and e cases share the same code in the function that handles unary operators, so I don't think it's an accidental thing.

                    – jjlin
                    Jun 17 '14 at 17:33


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Super User!


                    • 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%2fsuperuser.com%2fquestions%2f769670%2fwhats-linux-test-a-command-test-for%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

                    Probability when a professor distributes a quiz and homework assignment to a class of n students.

                    Aardman Animations

                    Are they similar matrix