Color codes for echo don't work when running a script over ssh

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











up vote
0
down vote

favorite












all.



I have the following exemple code:



#!/bin/bash
echo "[33[01;32m green 33[01;37m]"
echo "[33[01;31m red 33[01;37m]"


When I run this script locally, I get the correct output color.



But if I copy to another host over scp and run it with "ssh avadmin@10.224.1.6 "sudo sh color-test.sh"" the script will print the code instead of the color.



Should I have any considerations when running script remotely?










share|improve this question

























    up vote
    0
    down vote

    favorite












    all.



    I have the following exemple code:



    #!/bin/bash
    echo "[33[01;32m green 33[01;37m]"
    echo "[33[01;31m red 33[01;37m]"


    When I run this script locally, I get the correct output color.



    But if I copy to another host over scp and run it with "ssh avadmin@10.224.1.6 "sudo sh color-test.sh"" the script will print the code instead of the color.



    Should I have any considerations when running script remotely?










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      all.



      I have the following exemple code:



      #!/bin/bash
      echo "[33[01;32m green 33[01;37m]"
      echo "[33[01;31m red 33[01;37m]"


      When I run this script locally, I get the correct output color.



      But if I copy to another host over scp and run it with "ssh avadmin@10.224.1.6 "sudo sh color-test.sh"" the script will print the code instead of the color.



      Should I have any considerations when running script remotely?










      share|improve this question













      all.



      I have the following exemple code:



      #!/bin/bash
      echo "[33[01;32m green 33[01;37m]"
      echo "[33[01;31m red 33[01;37m]"


      When I run this script locally, I get the correct output color.



      But if I copy to another host over scp and run it with "ssh avadmin@10.224.1.6 "sudo sh color-test.sh"" the script will print the code instead of the color.



      Should I have any considerations when running script remotely?







      linux shell-script ssh






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 7 at 13:15









      Msalvatori

      135




      135




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          The behaviour of



          echo '33'


          Depends on the implementation and/or the environment.



          With UNIX-compliant implementations, it outputs a ESC character followed by NL, in some others, it outputs 33 followed by NL. Some support a -e option for those 33 escape sequences to be expanded.



          Your script has a #! /bin/bash she-bang, but you're running the script as sh the-script, so sh interprets it, not bash.



          On most systems, bash's echo builtin doesn't expand x sequences by default. It only does so when the xpg_echo option is enabled or by using the -e option (unless both the xpg_echo and posix options have been enabled).



          Probably your local sh implementation is a UNIX-compliant one in that regard (like dash, or bash compiled with the xpg_echo option enabled by default), but the one on the remote server is not (like bash).



          If you want a portable and reliable behaviour, use printf instead:



          printf '[33[01;32m green 33[01;37m]n'
          printf '[33[01;31m red 33[01;37m]n'





          share|improve this answer




















          • Further reading is, of course, unix.stackexchange.com/a/65819/5132 .
            – JdeBP
            Aug 7 at 13:50










          • @JdeBP, it's already referenced in the answer.
            – Stéphane Chazelas
            Aug 7 at 14:13










          • So it is. I failed to spot that.
            – JdeBP
            Aug 7 at 15:58










          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
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f461071%2fcolor-codes-for-echo-dont-work-when-running-a-script-over-ssh%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
          3
          down vote



          accepted










          The behaviour of



          echo '33'


          Depends on the implementation and/or the environment.



          With UNIX-compliant implementations, it outputs a ESC character followed by NL, in some others, it outputs 33 followed by NL. Some support a -e option for those 33 escape sequences to be expanded.



          Your script has a #! /bin/bash she-bang, but you're running the script as sh the-script, so sh interprets it, not bash.



          On most systems, bash's echo builtin doesn't expand x sequences by default. It only does so when the xpg_echo option is enabled or by using the -e option (unless both the xpg_echo and posix options have been enabled).



          Probably your local sh implementation is a UNIX-compliant one in that regard (like dash, or bash compiled with the xpg_echo option enabled by default), but the one on the remote server is not (like bash).



          If you want a portable and reliable behaviour, use printf instead:



          printf '[33[01;32m green 33[01;37m]n'
          printf '[33[01;31m red 33[01;37m]n'





          share|improve this answer




















          • Further reading is, of course, unix.stackexchange.com/a/65819/5132 .
            – JdeBP
            Aug 7 at 13:50










          • @JdeBP, it's already referenced in the answer.
            – Stéphane Chazelas
            Aug 7 at 14:13










          • So it is. I failed to spot that.
            – JdeBP
            Aug 7 at 15:58














          up vote
          3
          down vote



          accepted










          The behaviour of



          echo '33'


          Depends on the implementation and/or the environment.



          With UNIX-compliant implementations, it outputs a ESC character followed by NL, in some others, it outputs 33 followed by NL. Some support a -e option for those 33 escape sequences to be expanded.



          Your script has a #! /bin/bash she-bang, but you're running the script as sh the-script, so sh interprets it, not bash.



          On most systems, bash's echo builtin doesn't expand x sequences by default. It only does so when the xpg_echo option is enabled or by using the -e option (unless both the xpg_echo and posix options have been enabled).



          Probably your local sh implementation is a UNIX-compliant one in that regard (like dash, or bash compiled with the xpg_echo option enabled by default), but the one on the remote server is not (like bash).



          If you want a portable and reliable behaviour, use printf instead:



          printf '[33[01;32m green 33[01;37m]n'
          printf '[33[01;31m red 33[01;37m]n'





          share|improve this answer




















          • Further reading is, of course, unix.stackexchange.com/a/65819/5132 .
            – JdeBP
            Aug 7 at 13:50










          • @JdeBP, it's already referenced in the answer.
            – Stéphane Chazelas
            Aug 7 at 14:13










          • So it is. I failed to spot that.
            – JdeBP
            Aug 7 at 15:58












          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          The behaviour of



          echo '33'


          Depends on the implementation and/or the environment.



          With UNIX-compliant implementations, it outputs a ESC character followed by NL, in some others, it outputs 33 followed by NL. Some support a -e option for those 33 escape sequences to be expanded.



          Your script has a #! /bin/bash she-bang, but you're running the script as sh the-script, so sh interprets it, not bash.



          On most systems, bash's echo builtin doesn't expand x sequences by default. It only does so when the xpg_echo option is enabled or by using the -e option (unless both the xpg_echo and posix options have been enabled).



          Probably your local sh implementation is a UNIX-compliant one in that regard (like dash, or bash compiled with the xpg_echo option enabled by default), but the one on the remote server is not (like bash).



          If you want a portable and reliable behaviour, use printf instead:



          printf '[33[01;32m green 33[01;37m]n'
          printf '[33[01;31m red 33[01;37m]n'





          share|improve this answer












          The behaviour of



          echo '33'


          Depends on the implementation and/or the environment.



          With UNIX-compliant implementations, it outputs a ESC character followed by NL, in some others, it outputs 33 followed by NL. Some support a -e option for those 33 escape sequences to be expanded.



          Your script has a #! /bin/bash she-bang, but you're running the script as sh the-script, so sh interprets it, not bash.



          On most systems, bash's echo builtin doesn't expand x sequences by default. It only does so when the xpg_echo option is enabled or by using the -e option (unless both the xpg_echo and posix options have been enabled).



          Probably your local sh implementation is a UNIX-compliant one in that regard (like dash, or bash compiled with the xpg_echo option enabled by default), but the one on the remote server is not (like bash).



          If you want a portable and reliable behaviour, use printf instead:



          printf '[33[01;32m green 33[01;37m]n'
          printf '[33[01;31m red 33[01;37m]n'






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 7 at 13:27









          Stéphane Chazelas

          284k53523861




          284k53523861











          • Further reading is, of course, unix.stackexchange.com/a/65819/5132 .
            – JdeBP
            Aug 7 at 13:50










          • @JdeBP, it's already referenced in the answer.
            – Stéphane Chazelas
            Aug 7 at 14:13










          • So it is. I failed to spot that.
            – JdeBP
            Aug 7 at 15:58
















          • Further reading is, of course, unix.stackexchange.com/a/65819/5132 .
            – JdeBP
            Aug 7 at 13:50










          • @JdeBP, it's already referenced in the answer.
            – Stéphane Chazelas
            Aug 7 at 14:13










          • So it is. I failed to spot that.
            – JdeBP
            Aug 7 at 15:58















          Further reading is, of course, unix.stackexchange.com/a/65819/5132 .
          – JdeBP
          Aug 7 at 13:50




          Further reading is, of course, unix.stackexchange.com/a/65819/5132 .
          – JdeBP
          Aug 7 at 13:50












          @JdeBP, it's already referenced in the answer.
          – Stéphane Chazelas
          Aug 7 at 14:13




          @JdeBP, it's already referenced in the answer.
          – Stéphane Chazelas
          Aug 7 at 14:13












          So it is. I failed to spot that.
          – JdeBP
          Aug 7 at 15:58




          So it is. I failed to spot that.
          – JdeBP
          Aug 7 at 15:58

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f461071%2fcolor-codes-for-echo-dont-work-when-running-a-script-over-ssh%23new-answer', 'question_page');

          );

          Post as a guest













































































          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