Color codes for echo don't work when running a script over ssh
Clash 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?
linux shell-script ssh
add a comment |Â
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?
linux shell-script ssh
add a comment |Â
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?
linux shell-script ssh
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
linux shell-script ssh
asked Aug 7 at 13:15
Msalvatori
135
135
add a comment |Â
add a comment |Â
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'
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
add a comment |Â
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'
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
add a comment |Â
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'
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
add a comment |Â
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'
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'
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password