&> test or > test 2>&1

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I read from an instruction using &> to handle errors and data



$ls -al test test2 test3 badtest &> test7
$ cat test7
ls: cannot access 'test': No such file or directory
ls: cannot access 'badtest': No such file or directory
-rw-r--r-- 1 me staff 78 Oct 28 19:07 test2
-rw-r--r-- 1 me staff 0 Oct 28 19:03 test3


Nonetheless, when I check Obsolete and deprecated syntax [Bash Hackers Wiki]



It recommends 2>&1



$ ls -al test test2 test3 badtest > test7 2>&1

$ cat test7
ls: cannot access 'test': No such file or directory
ls: cannot access 'badtest': No such file or directory
-rw-r--r-- 1 me staff 78 Oct 28 19:07 test2
-rw-r--r-- 1 me staff 0 Oct 28 19:03 test3


Which pattern should I follow










share|improve this question







New contributor




avirate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    2
    down vote

    favorite












    I read from an instruction using &> to handle errors and data



    $ls -al test test2 test3 badtest &> test7
    $ cat test7
    ls: cannot access 'test': No such file or directory
    ls: cannot access 'badtest': No such file or directory
    -rw-r--r-- 1 me staff 78 Oct 28 19:07 test2
    -rw-r--r-- 1 me staff 0 Oct 28 19:03 test3


    Nonetheless, when I check Obsolete and deprecated syntax [Bash Hackers Wiki]



    It recommends 2>&1



    $ ls -al test test2 test3 badtest > test7 2>&1

    $ cat test7
    ls: cannot access 'test': No such file or directory
    ls: cannot access 'badtest': No such file or directory
    -rw-r--r-- 1 me staff 78 Oct 28 19:07 test2
    -rw-r--r-- 1 me staff 0 Oct 28 19:03 test3


    Which pattern should I follow










    share|improve this question







    New contributor




    avirate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I read from an instruction using &> to handle errors and data



      $ls -al test test2 test3 badtest &> test7
      $ cat test7
      ls: cannot access 'test': No such file or directory
      ls: cannot access 'badtest': No such file or directory
      -rw-r--r-- 1 me staff 78 Oct 28 19:07 test2
      -rw-r--r-- 1 me staff 0 Oct 28 19:03 test3


      Nonetheless, when I check Obsolete and deprecated syntax [Bash Hackers Wiki]



      It recommends 2>&1



      $ ls -al test test2 test3 badtest > test7 2>&1

      $ cat test7
      ls: cannot access 'test': No such file or directory
      ls: cannot access 'badtest': No such file or directory
      -rw-r--r-- 1 me staff 78 Oct 28 19:07 test2
      -rw-r--r-- 1 me staff 0 Oct 28 19:03 test3


      Which pattern should I follow










      share|improve this question







      New contributor




      avirate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I read from an instruction using &> to handle errors and data



      $ls -al test test2 test3 badtest &> test7
      $ cat test7
      ls: cannot access 'test': No such file or directory
      ls: cannot access 'badtest': No such file or directory
      -rw-r--r-- 1 me staff 78 Oct 28 19:07 test2
      -rw-r--r-- 1 me staff 0 Oct 28 19:03 test3


      Nonetheless, when I check Obsolete and deprecated syntax [Bash Hackers Wiki]



      It recommends 2>&1



      $ ls -al test test2 test3 badtest > test7 2>&1

      $ cat test7
      ls: cannot access 'test': No such file or directory
      ls: cannot access 'badtest': No such file or directory
      -rw-r--r-- 1 me staff 78 Oct 28 19:07 test2
      -rw-r--r-- 1 me staff 0 Oct 28 19:03 test3


      Which pattern should I follow







      bash






      share|improve this question







      New contributor




      avirate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      avirate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      avirate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 47 mins ago









      avirate

      39329




      39329




      New contributor




      avirate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      avirate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      avirate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          This is up to you to decide.



          The bash shell understands &>file and >file 2>&1 as identical and you may use the former syntax as a shortcut way of writing the latter. Other shells may throw a syntax error or do something unexpected with &>.



          If you only write bash scripts (and not scripts for e.g. /bin/sh), then by all means use &>, but if you find yourself wanting or needing to write portable scripts (scripts that need to run under /bin/sh or that should be executable by any sh-like shell, of which bash is one and ksh, zsh and dash are others), then &> is one of the things you should avoid.



          All sh-like shells implement the POSIX standard in terms of syntax and grammar, but bash and other shells also provides syntactic conveniences like &> and extensions like arrays and regular expression matching etc., and some shells may expand on the POSIX standard quite differently from the way bash is doing it.



          Related:




          • Other questions on this site about bash and portability (DuckDuckGo search link).





          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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );






            avirate is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f478238%2ftest-or-test-21%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            4
            down vote



            accepted










            This is up to you to decide.



            The bash shell understands &>file and >file 2>&1 as identical and you may use the former syntax as a shortcut way of writing the latter. Other shells may throw a syntax error or do something unexpected with &>.



            If you only write bash scripts (and not scripts for e.g. /bin/sh), then by all means use &>, but if you find yourself wanting or needing to write portable scripts (scripts that need to run under /bin/sh or that should be executable by any sh-like shell, of which bash is one and ksh, zsh and dash are others), then &> is one of the things you should avoid.



            All sh-like shells implement the POSIX standard in terms of syntax and grammar, but bash and other shells also provides syntactic conveniences like &> and extensions like arrays and regular expression matching etc., and some shells may expand on the POSIX standard quite differently from the way bash is doing it.



            Related:




            • Other questions on this site about bash and portability (DuckDuckGo search link).





            share|improve this answer


























              up vote
              4
              down vote



              accepted










              This is up to you to decide.



              The bash shell understands &>file and >file 2>&1 as identical and you may use the former syntax as a shortcut way of writing the latter. Other shells may throw a syntax error or do something unexpected with &>.



              If you only write bash scripts (and not scripts for e.g. /bin/sh), then by all means use &>, but if you find yourself wanting or needing to write portable scripts (scripts that need to run under /bin/sh or that should be executable by any sh-like shell, of which bash is one and ksh, zsh and dash are others), then &> is one of the things you should avoid.



              All sh-like shells implement the POSIX standard in terms of syntax and grammar, but bash and other shells also provides syntactic conveniences like &> and extensions like arrays and regular expression matching etc., and some shells may expand on the POSIX standard quite differently from the way bash is doing it.



              Related:




              • Other questions on this site about bash and portability (DuckDuckGo search link).





              share|improve this answer
























                up vote
                4
                down vote



                accepted







                up vote
                4
                down vote



                accepted






                This is up to you to decide.



                The bash shell understands &>file and >file 2>&1 as identical and you may use the former syntax as a shortcut way of writing the latter. Other shells may throw a syntax error or do something unexpected with &>.



                If you only write bash scripts (and not scripts for e.g. /bin/sh), then by all means use &>, but if you find yourself wanting or needing to write portable scripts (scripts that need to run under /bin/sh or that should be executable by any sh-like shell, of which bash is one and ksh, zsh and dash are others), then &> is one of the things you should avoid.



                All sh-like shells implement the POSIX standard in terms of syntax and grammar, but bash and other shells also provides syntactic conveniences like &> and extensions like arrays and regular expression matching etc., and some shells may expand on the POSIX standard quite differently from the way bash is doing it.



                Related:




                • Other questions on this site about bash and portability (DuckDuckGo search link).





                share|improve this answer














                This is up to you to decide.



                The bash shell understands &>file and >file 2>&1 as identical and you may use the former syntax as a shortcut way of writing the latter. Other shells may throw a syntax error or do something unexpected with &>.



                If you only write bash scripts (and not scripts for e.g. /bin/sh), then by all means use &>, but if you find yourself wanting or needing to write portable scripts (scripts that need to run under /bin/sh or that should be executable by any sh-like shell, of which bash is one and ksh, zsh and dash are others), then &> is one of the things you should avoid.



                All sh-like shells implement the POSIX standard in terms of syntax and grammar, but bash and other shells also provides syntactic conveniences like &> and extensions like arrays and regular expression matching etc., and some shells may expand on the POSIX standard quite differently from the way bash is doing it.



                Related:




                • Other questions on this site about bash and portability (DuckDuckGo search link).






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 1 min ago

























                answered 39 mins ago









                Kusalananda

                112k15216343




                112k15216343




















                    avirate is a new contributor. Be nice, and check out our Code of Conduct.









                     

                    draft saved


                    draft discarded


















                    avirate is a new contributor. Be nice, and check out our Code of Conduct.












                    avirate is a new contributor. Be nice, and check out our Code of Conduct.











                    avirate is a new contributor. Be nice, and check out our Code of Conduct.













                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f478238%2ftest-or-test-21%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    List of Gilmore Girls characters

                    Confectionery