how to echo $, & symbols correctly?











up vote
0
down vote

favorite












Output &a on the screen while there is already a defined variable a. Here is what happened in my bash:



localhost:~ $ a=5
localhost:~ $ echo $$a
83079a
localhost:~ $ echo ^$a
^5
localhost:~ $


I just can't get $a.



And I found this post: https://stackoverflow.com/questions/4087695/escaping-ampersands-in-windows-batch-files



it says echo a ^& b will get a & b, but with my bash I got this:



localhost:~ $ echo a ^& b
[1] 83134
a ^
-bash: b: command not found









share|improve this question




















  • 3




    did you try to excape using back slash instead of '^' ?
    – lese
    Sep 4 '15 at 14:03












  • works. thanks! sorry I never thought of that ...
    – AGamePlayer
    Sep 4 '15 at 14:04










  • You can also place things in single quotes ' to get the literal form of anything
    – Centimane
    Sep 4 '15 at 14:06










  • You shouldn't be looking at windows batch file information for help with bash. They are different things.
    – jw013
    Sep 4 '15 at 14:55















up vote
0
down vote

favorite












Output &a on the screen while there is already a defined variable a. Here is what happened in my bash:



localhost:~ $ a=5
localhost:~ $ echo $$a
83079a
localhost:~ $ echo ^$a
^5
localhost:~ $


I just can't get $a.



And I found this post: https://stackoverflow.com/questions/4087695/escaping-ampersands-in-windows-batch-files



it says echo a ^& b will get a & b, but with my bash I got this:



localhost:~ $ echo a ^& b
[1] 83134
a ^
-bash: b: command not found









share|improve this question




















  • 3




    did you try to excape using back slash instead of '^' ?
    – lese
    Sep 4 '15 at 14:03












  • works. thanks! sorry I never thought of that ...
    – AGamePlayer
    Sep 4 '15 at 14:04










  • You can also place things in single quotes ' to get the literal form of anything
    – Centimane
    Sep 4 '15 at 14:06










  • You shouldn't be looking at windows batch file information for help with bash. They are different things.
    – jw013
    Sep 4 '15 at 14:55













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Output &a on the screen while there is already a defined variable a. Here is what happened in my bash:



localhost:~ $ a=5
localhost:~ $ echo $$a
83079a
localhost:~ $ echo ^$a
^5
localhost:~ $


I just can't get $a.



And I found this post: https://stackoverflow.com/questions/4087695/escaping-ampersands-in-windows-batch-files



it says echo a ^& b will get a & b, but with my bash I got this:



localhost:~ $ echo a ^& b
[1] 83134
a ^
-bash: b: command not found









share|improve this question















Output &a on the screen while there is already a defined variable a. Here is what happened in my bash:



localhost:~ $ a=5
localhost:~ $ echo $$a
83079a
localhost:~ $ echo ^$a
^5
localhost:~ $


I just can't get $a.



And I found this post: https://stackoverflow.com/questions/4087695/escaping-ampersands-in-windows-batch-files



it says echo a ^& b will get a & b, but with my bash I got this:



localhost:~ $ echo a ^& b
[1] 83134
a ^
-bash: b: command not found






shell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









Rui F Ribeiro

38.6k1479128




38.6k1479128










asked Sep 4 '15 at 13:56









AGamePlayer

1,976102942




1,976102942








  • 3




    did you try to excape using back slash instead of '^' ?
    – lese
    Sep 4 '15 at 14:03












  • works. thanks! sorry I never thought of that ...
    – AGamePlayer
    Sep 4 '15 at 14:04










  • You can also place things in single quotes ' to get the literal form of anything
    – Centimane
    Sep 4 '15 at 14:06










  • You shouldn't be looking at windows batch file information for help with bash. They are different things.
    – jw013
    Sep 4 '15 at 14:55














  • 3




    did you try to excape using back slash instead of '^' ?
    – lese
    Sep 4 '15 at 14:03












  • works. thanks! sorry I never thought of that ...
    – AGamePlayer
    Sep 4 '15 at 14:04










  • You can also place things in single quotes ' to get the literal form of anything
    – Centimane
    Sep 4 '15 at 14:06










  • You shouldn't be looking at windows batch file information for help with bash. They are different things.
    – jw013
    Sep 4 '15 at 14:55








3




3




did you try to excape using back slash instead of '^' ?
– lese
Sep 4 '15 at 14:03






did you try to excape using back slash instead of '^' ?
– lese
Sep 4 '15 at 14:03














works. thanks! sorry I never thought of that ...
– AGamePlayer
Sep 4 '15 at 14:04




works. thanks! sorry I never thought of that ...
– AGamePlayer
Sep 4 '15 at 14:04












You can also place things in single quotes ' to get the literal form of anything
– Centimane
Sep 4 '15 at 14:06




You can also place things in single quotes ' to get the literal form of anything
– Centimane
Sep 4 '15 at 14:06












You shouldn't be looking at windows batch file information for help with bash. They are different things.
– jw013
Sep 4 '15 at 14:55




You shouldn't be looking at windows batch file information for help with bash. They are different things.
– jw013
Sep 4 '15 at 14:55










2 Answers
2






active

oldest

votes

















up vote
4
down vote



accepted










Use double quotes to echo a variable



localhost:~ $ a=5
localhost:~ $ echo "$a"
5
localhost:~ $ echo '$a'
$a
localhost:~ $ echo "a & b"
a & b


Or backslash to escape and not use quotes



localhost:~ $ echo a & b
a & b
localhost:~ $ echo $a
$a





share|improve this answer






























    up vote
    0
    down vote













    r@S:/tmp # a=10
    r@S:/tmp # echo $a
    10
    r@S:/tmp # echo $a
    $a
    r@S:/tmp #





    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: 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%2f227516%2fhow-to-echo-symbols-correctly%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










      Use double quotes to echo a variable



      localhost:~ $ a=5
      localhost:~ $ echo "$a"
      5
      localhost:~ $ echo '$a'
      $a
      localhost:~ $ echo "a & b"
      a & b


      Or backslash to escape and not use quotes



      localhost:~ $ echo a & b
      a & b
      localhost:~ $ echo $a
      $a





      share|improve this answer



























        up vote
        4
        down vote



        accepted










        Use double quotes to echo a variable



        localhost:~ $ a=5
        localhost:~ $ echo "$a"
        5
        localhost:~ $ echo '$a'
        $a
        localhost:~ $ echo "a & b"
        a & b


        Or backslash to escape and not use quotes



        localhost:~ $ echo a & b
        a & b
        localhost:~ $ echo $a
        $a





        share|improve this answer

























          up vote
          4
          down vote



          accepted







          up vote
          4
          down vote



          accepted






          Use double quotes to echo a variable



          localhost:~ $ a=5
          localhost:~ $ echo "$a"
          5
          localhost:~ $ echo '$a'
          $a
          localhost:~ $ echo "a & b"
          a & b


          Or backslash to escape and not use quotes



          localhost:~ $ echo a & b
          a & b
          localhost:~ $ echo $a
          $a





          share|improve this answer














          Use double quotes to echo a variable



          localhost:~ $ a=5
          localhost:~ $ echo "$a"
          5
          localhost:~ $ echo '$a'
          $a
          localhost:~ $ echo "a & b"
          a & b


          Or backslash to escape and not use quotes



          localhost:~ $ echo a & b
          a & b
          localhost:~ $ echo $a
          $a






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Sep 4 '15 at 14:25

























          answered Sep 4 '15 at 14:17









          tachomi

          3,56731134




          3,56731134
























              up vote
              0
              down vote













              r@S:/tmp # a=10
              r@S:/tmp # echo $a
              10
              r@S:/tmp # echo $a
              $a
              r@S:/tmp #





              share|improve this answer

























                up vote
                0
                down vote













                r@S:/tmp # a=10
                r@S:/tmp # echo $a
                10
                r@S:/tmp # echo $a
                $a
                r@S:/tmp #





                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  r@S:/tmp # a=10
                  r@S:/tmp # echo $a
                  10
                  r@S:/tmp # echo $a
                  $a
                  r@S:/tmp #





                  share|improve this answer












                  r@S:/tmp # a=10
                  r@S:/tmp # echo $a
                  10
                  r@S:/tmp # echo $a
                  $a
                  r@S:/tmp #






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 4 '15 at 14:20









                  SHW

                  7,98633570




                  7,98633570






























                      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%2f227516%2fhow-to-echo-symbols-correctly%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

                      サソリ

                      広島県道265号伴広島線

                      Setup Asymptote in Texstudio