Meaning of backslash

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












3















Why the following command prints Smith but not Smith?



echo Smith









share|improve this question


























    3















    Why the following command prints Smith but not Smith?



    echo Smith









    share|improve this question
























      3












      3








      3








      Why the following command prints Smith but not Smith?



      echo Smith









      share|improve this question














      Why the following command prints Smith but not Smith?



      echo Smith






      bash escape-characters






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jul 26 '14 at 0:48









      DUKEDUKE

      2372510




      2372510




















          2 Answers
          2






          active

          oldest

          votes


















          5














          The backslash is an escape character in the shell syntax that:




          shall preserve the literal value of the following character, with the exception of a <newline>. ... The <backslash> ... shall be removed




          So S means the same thing as S, because S is not a newline character and also not a shell special character that could be escaped ($, ", ', {, [, `, , |, &, ;, <, >, (, ), ?, *, [, #, ~, =, %, , or tab). To include a literal backslash in the argument given to echo, escape it in turn with or any other quoting operator:



          echo \Smith


          or



          echo 'Smith'


          or



          echo "Smith"


          ( still retains a special meaning within double quotes, but not when followed by S, only when followed by , `, $, " or newline).



          Now, many echo implementations also treat specially when found in their argument (though generally not when followed by S, though there's no guarantee), so you may want to use printf instead:



          printf '%sn' 'Smith'


          note: this is the specified behavior for your example unquoted case, but it can change if it is otherwise quoted or read in from a file






          share|improve this answer
































            2














            S escapes the S, which is not a special character, thus gives S. You need to double the backslash to print it: echo \Smith



            EDIT: But more generally, it's better to use printf. See the difference between echo x\by, which outputs "y" (the "x" gets overwritten by the backspace b) with some versions of echo (dash, zsh), and printf "%sn" x\by, which outputs "xby".






            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%2f146663%2fmeaning-of-backslash%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









              5














              The backslash is an escape character in the shell syntax that:




              shall preserve the literal value of the following character, with the exception of a <newline>. ... The <backslash> ... shall be removed




              So S means the same thing as S, because S is not a newline character and also not a shell special character that could be escaped ($, ", ', {, [, `, , |, &, ;, <, >, (, ), ?, *, [, #, ~, =, %, , or tab). To include a literal backslash in the argument given to echo, escape it in turn with or any other quoting operator:



              echo \Smith


              or



              echo 'Smith'


              or



              echo "Smith"


              ( still retains a special meaning within double quotes, but not when followed by S, only when followed by , `, $, " or newline).



              Now, many echo implementations also treat specially when found in their argument (though generally not when followed by S, though there's no guarantee), so you may want to use printf instead:



              printf '%sn' 'Smith'


              note: this is the specified behavior for your example unquoted case, but it can change if it is otherwise quoted or read in from a file






              share|improve this answer





























                5














                The backslash is an escape character in the shell syntax that:




                shall preserve the literal value of the following character, with the exception of a <newline>. ... The <backslash> ... shall be removed




                So S means the same thing as S, because S is not a newline character and also not a shell special character that could be escaped ($, ", ', {, [, `, , |, &, ;, <, >, (, ), ?, *, [, #, ~, =, %, , or tab). To include a literal backslash in the argument given to echo, escape it in turn with or any other quoting operator:



                echo \Smith


                or



                echo 'Smith'


                or



                echo "Smith"


                ( still retains a special meaning within double quotes, but not when followed by S, only when followed by , `, $, " or newline).



                Now, many echo implementations also treat specially when found in their argument (though generally not when followed by S, though there's no guarantee), so you may want to use printf instead:



                printf '%sn' 'Smith'


                note: this is the specified behavior for your example unquoted case, but it can change if it is otherwise quoted or read in from a file






                share|improve this answer



























                  5












                  5








                  5







                  The backslash is an escape character in the shell syntax that:




                  shall preserve the literal value of the following character, with the exception of a <newline>. ... The <backslash> ... shall be removed




                  So S means the same thing as S, because S is not a newline character and also not a shell special character that could be escaped ($, ", ', {, [, `, , |, &, ;, <, >, (, ), ?, *, [, #, ~, =, %, , or tab). To include a literal backslash in the argument given to echo, escape it in turn with or any other quoting operator:



                  echo \Smith


                  or



                  echo 'Smith'


                  or



                  echo "Smith"


                  ( still retains a special meaning within double quotes, but not when followed by S, only when followed by , `, $, " or newline).



                  Now, many echo implementations also treat specially when found in their argument (though generally not when followed by S, though there's no guarantee), so you may want to use printf instead:



                  printf '%sn' 'Smith'


                  note: this is the specified behavior for your example unquoted case, but it can change if it is otherwise quoted or read in from a file






                  share|improve this answer















                  The backslash is an escape character in the shell syntax that:




                  shall preserve the literal value of the following character, with the exception of a <newline>. ... The <backslash> ... shall be removed




                  So S means the same thing as S, because S is not a newline character and also not a shell special character that could be escaped ($, ", ', {, [, `, , |, &, ;, <, >, (, ), ?, *, [, #, ~, =, %, , or tab). To include a literal backslash in the argument given to echo, escape it in turn with or any other quoting operator:



                  echo \Smith


                  or



                  echo 'Smith'


                  or



                  echo "Smith"


                  ( still retains a special meaning within double quotes, but not when followed by S, only when followed by , `, $, " or newline).



                  Now, many echo implementations also treat specially when found in their argument (though generally not when followed by S, though there's no guarantee), so you may want to use printf instead:



                  printf '%sn' 'Smith'


                  note: this is the specified behavior for your example unquoted case, but it can change if it is otherwise quoted or read in from a file







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Feb 1 at 10:17









                  Stéphane Chazelas

                  306k57581935




                  306k57581935










                  answered Jul 26 '14 at 0:53









                  Michael HomerMichael Homer

                  48.7k8130168




                  48.7k8130168























                      2














                      S escapes the S, which is not a special character, thus gives S. You need to double the backslash to print it: echo \Smith



                      EDIT: But more generally, it's better to use printf. See the difference between echo x\by, which outputs "y" (the "x" gets overwritten by the backspace b) with some versions of echo (dash, zsh), and printf "%sn" x\by, which outputs "xby".






                      share|improve this answer





























                        2














                        S escapes the S, which is not a special character, thus gives S. You need to double the backslash to print it: echo \Smith



                        EDIT: But more generally, it's better to use printf. See the difference between echo x\by, which outputs "y" (the "x" gets overwritten by the backspace b) with some versions of echo (dash, zsh), and printf "%sn" x\by, which outputs "xby".






                        share|improve this answer



























                          2












                          2








                          2







                          S escapes the S, which is not a special character, thus gives S. You need to double the backslash to print it: echo \Smith



                          EDIT: But more generally, it's better to use printf. See the difference between echo x\by, which outputs "y" (the "x" gets overwritten by the backspace b) with some versions of echo (dash, zsh), and printf "%sn" x\by, which outputs "xby".






                          share|improve this answer















                          S escapes the S, which is not a special character, thus gives S. You need to double the backslash to print it: echo \Smith



                          EDIT: But more generally, it's better to use printf. See the difference between echo x\by, which outputs "y" (the "x" gets overwritten by the backspace b) with some versions of echo (dash, zsh), and printf "%sn" x\by, which outputs "xby".







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Jul 26 '14 at 0:58

























                          answered Jul 26 '14 at 0:53









                          vinc17vinc17

                          8,9991736




                          8,9991736



























                              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%2f146663%2fmeaning-of-backslash%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

                              How to check contact read email or not when send email to Individual?

                              Bahrain

                              Postfix configuration issue with fips on centos 7; mailgun relay