An echo operation includes some piece of text it should not include











up vote
0
down vote

favorite












On a WSL Ubuntu 16.04 (Xenial) with composer I executed:



echo 2 * 3 > 5 is a valid inequality 


It resulted in a file by the name of 5, with the content:




2 composer-setup.php 3 is a valid inequality




I don't know why this echo includes the text composer-setup.php as well; it should have included everything from left and right besides 5 (the file name) as echo can have a single stream of text as its file name for redirection (no spaces allowed, as I understand, hence the 5 name).



Why is the composer-setup.php appears there between the 2 and 3?










share|improve this question




























    up vote
    0
    down vote

    favorite












    On a WSL Ubuntu 16.04 (Xenial) with composer I executed:



    echo 2 * 3 > 5 is a valid inequality 


    It resulted in a file by the name of 5, with the content:




    2 composer-setup.php 3 is a valid inequality




    I don't know why this echo includes the text composer-setup.php as well; it should have included everything from left and right besides 5 (the file name) as echo can have a single stream of text as its file name for redirection (no spaces allowed, as I understand, hence the 5 name).



    Why is the composer-setup.php appears there between the 2 and 3?










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      On a WSL Ubuntu 16.04 (Xenial) with composer I executed:



      echo 2 * 3 > 5 is a valid inequality 


      It resulted in a file by the name of 5, with the content:




      2 composer-setup.php 3 is a valid inequality




      I don't know why this echo includes the text composer-setup.php as well; it should have included everything from left and right besides 5 (the file name) as echo can have a single stream of text as its file name for redirection (no spaces allowed, as I understand, hence the 5 name).



      Why is the composer-setup.php appears there between the 2 and 3?










      share|improve this question















      On a WSL Ubuntu 16.04 (Xenial) with composer I executed:



      echo 2 * 3 > 5 is a valid inequality 


      It resulted in a file by the name of 5, with the content:




      2 composer-setup.php 3 is a valid inequality




      I don't know why this echo includes the text composer-setup.php as well; it should have included everything from left and right besides 5 (the file name) as echo can have a single stream of text as its file name for redirection (no spaces allowed, as I understand, hence the 5 name).



      Why is the composer-setup.php appears there between the 2 and 3?







      shell wildcards echo






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 8 at 17:33









      terdon

      127k31246423




      127k31246423










      asked Dec 7 at 19:58









      JohnDoea

      1151132




      1151132






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          You've executed a commandline that has two shell-special characters in it: * and >. You saw what > did; the * is a wildcard / globbing character that picked up every1 file in your current directory. You have one file, named composer-setup.php in your current directory.



          Quote your commandline; single-quotes work if there are no single-quotes in your text:



          echo '2 * 3 > 5 is a valid inequality'


          1: every file (or directory, socket, etc) that doesn't start with a period, unless you've set a shell option (such as dotglob) to specifically enable dot-file globbing.






          share|improve this answer























          • @John, regarding your suggested edit, the wildcard/glob picks up directories and sockets and pipes, etc. -- not just "regular files"
            – Jeff Schaller
            Dec 8 at 12:49


















          up vote
          4
          down vote













          There are two things happening here...



          First is that the shell sees the * character and replaces it with a list of files in the current directory. This is known as "globbing"



          In addition the > 5 is seen as a redirection command.



          so



          echo 2 * 3 > 5 is a valid inequality 


          Is parsed as



          echo 2 * 3 is a valid inequality > 5


          This results in a file called "5" being created with the contents "2 list of current files 3 is a valid inequality".



          To prevent this from happening we need to use quotes



          echo '2 * 3 > 5 is a valid inequality'


          The '...' prevents the shell from interpreting the special characters and displays the string you entered.






          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%2f486659%2fan-echo-operation-includes-some-piece-of-text-it-should-not-include%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            4
            down vote



            accepted










            You've executed a commandline that has two shell-special characters in it: * and >. You saw what > did; the * is a wildcard / globbing character that picked up every1 file in your current directory. You have one file, named composer-setup.php in your current directory.



            Quote your commandline; single-quotes work if there are no single-quotes in your text:



            echo '2 * 3 > 5 is a valid inequality'


            1: every file (or directory, socket, etc) that doesn't start with a period, unless you've set a shell option (such as dotglob) to specifically enable dot-file globbing.






            share|improve this answer























            • @John, regarding your suggested edit, the wildcard/glob picks up directories and sockets and pipes, etc. -- not just "regular files"
              – Jeff Schaller
              Dec 8 at 12:49















            up vote
            4
            down vote



            accepted










            You've executed a commandline that has two shell-special characters in it: * and >. You saw what > did; the * is a wildcard / globbing character that picked up every1 file in your current directory. You have one file, named composer-setup.php in your current directory.



            Quote your commandline; single-quotes work if there are no single-quotes in your text:



            echo '2 * 3 > 5 is a valid inequality'


            1: every file (or directory, socket, etc) that doesn't start with a period, unless you've set a shell option (such as dotglob) to specifically enable dot-file globbing.






            share|improve this answer























            • @John, regarding your suggested edit, the wildcard/glob picks up directories and sockets and pipes, etc. -- not just "regular files"
              – Jeff Schaller
              Dec 8 at 12:49













            up vote
            4
            down vote



            accepted







            up vote
            4
            down vote



            accepted






            You've executed a commandline that has two shell-special characters in it: * and >. You saw what > did; the * is a wildcard / globbing character that picked up every1 file in your current directory. You have one file, named composer-setup.php in your current directory.



            Quote your commandline; single-quotes work if there are no single-quotes in your text:



            echo '2 * 3 > 5 is a valid inequality'


            1: every file (or directory, socket, etc) that doesn't start with a period, unless you've set a shell option (such as dotglob) to specifically enable dot-file globbing.






            share|improve this answer














            You've executed a commandline that has two shell-special characters in it: * and >. You saw what > did; the * is a wildcard / globbing character that picked up every1 file in your current directory. You have one file, named composer-setup.php in your current directory.



            Quote your commandline; single-quotes work if there are no single-quotes in your text:



            echo '2 * 3 > 5 is a valid inequality'


            1: every file (or directory, socket, etc) that doesn't start with a period, unless you've set a shell option (such as dotglob) to specifically enable dot-file globbing.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 8 at 12:48

























            answered Dec 7 at 20:13









            Jeff Schaller

            38.1k1053124




            38.1k1053124












            • @John, regarding your suggested edit, the wildcard/glob picks up directories and sockets and pipes, etc. -- not just "regular files"
              – Jeff Schaller
              Dec 8 at 12:49


















            • @John, regarding your suggested edit, the wildcard/glob picks up directories and sockets and pipes, etc. -- not just "regular files"
              – Jeff Schaller
              Dec 8 at 12:49
















            @John, regarding your suggested edit, the wildcard/glob picks up directories and sockets and pipes, etc. -- not just "regular files"
            – Jeff Schaller
            Dec 8 at 12:49




            @John, regarding your suggested edit, the wildcard/glob picks up directories and sockets and pipes, etc. -- not just "regular files"
            – Jeff Schaller
            Dec 8 at 12:49












            up vote
            4
            down vote













            There are two things happening here...



            First is that the shell sees the * character and replaces it with a list of files in the current directory. This is known as "globbing"



            In addition the > 5 is seen as a redirection command.



            so



            echo 2 * 3 > 5 is a valid inequality 


            Is parsed as



            echo 2 * 3 is a valid inequality > 5


            This results in a file called "5" being created with the contents "2 list of current files 3 is a valid inequality".



            To prevent this from happening we need to use quotes



            echo '2 * 3 > 5 is a valid inequality'


            The '...' prevents the shell from interpreting the special characters and displays the string you entered.






            share|improve this answer

























              up vote
              4
              down vote













              There are two things happening here...



              First is that the shell sees the * character and replaces it with a list of files in the current directory. This is known as "globbing"



              In addition the > 5 is seen as a redirection command.



              so



              echo 2 * 3 > 5 is a valid inequality 


              Is parsed as



              echo 2 * 3 is a valid inequality > 5


              This results in a file called "5" being created with the contents "2 list of current files 3 is a valid inequality".



              To prevent this from happening we need to use quotes



              echo '2 * 3 > 5 is a valid inequality'


              The '...' prevents the shell from interpreting the special characters and displays the string you entered.






              share|improve this answer























                up vote
                4
                down vote










                up vote
                4
                down vote









                There are two things happening here...



                First is that the shell sees the * character and replaces it with a list of files in the current directory. This is known as "globbing"



                In addition the > 5 is seen as a redirection command.



                so



                echo 2 * 3 > 5 is a valid inequality 


                Is parsed as



                echo 2 * 3 is a valid inequality > 5


                This results in a file called "5" being created with the contents "2 list of current files 3 is a valid inequality".



                To prevent this from happening we need to use quotes



                echo '2 * 3 > 5 is a valid inequality'


                The '...' prevents the shell from interpreting the special characters and displays the string you entered.






                share|improve this answer












                There are two things happening here...



                First is that the shell sees the * character and replaces it with a list of files in the current directory. This is known as "globbing"



                In addition the > 5 is seen as a redirection command.



                so



                echo 2 * 3 > 5 is a valid inequality 


                Is parsed as



                echo 2 * 3 is a valid inequality > 5


                This results in a file called "5" being created with the contents "2 list of current files 3 is a valid inequality".



                To prevent this from happening we need to use quotes



                echo '2 * 3 > 5 is a valid inequality'


                The '...' prevents the shell from interpreting the special characters and displays the string you entered.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 7 at 20:13









                Stephen Harris

                24.3k24477




                24.3k24477






























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2f486659%2fan-echo-operation-includes-some-piece-of-text-it-should-not-include%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

                    List directoties down one level, excluding some named directories and files

                    list processes belonging to a network namespace

                    list systemd RuntimeDirectory mounts