How to get osx shell script to show colors in echo
I'm trying to add color output to my errors in a bash script that I have running on a mac. The problem is the colors are not working. I created the simplest of scripts to demonstrate that it does not work:
#!/bin/bash
echo -e "e[1;31m This is red text e[0m"
However, when i run it, I see no colors at all, as shown in this image. The color output of the ls command is working fine however.
macos bash shell echo
add a comment |
I'm trying to add color output to my errors in a bash script that I have running on a mac. The problem is the colors are not working. I created the simplest of scripts to demonstrate that it does not work:
#!/bin/bash
echo -e "e[1;31m This is red text e[0m"
However, when i run it, I see no colors at all, as shown in this image. The color output of the ls command is working fine however.
macos bash shell echo
take a look at this, which I answered your question there: stackoverflow.com/a/48216286/3782119
– SHi ON
Jan 13 '18 at 23:39
I was happy to know that bash was old, and updating it solved my problem.
– nycynik
Jan 17 '18 at 13:58
add a comment |
I'm trying to add color output to my errors in a bash script that I have running on a mac. The problem is the colors are not working. I created the simplest of scripts to demonstrate that it does not work:
#!/bin/bash
echo -e "e[1;31m This is red text e[0m"
However, when i run it, I see no colors at all, as shown in this image. The color output of the ls command is working fine however.
macos bash shell echo
I'm trying to add color output to my errors in a bash script that I have running on a mac. The problem is the colors are not working. I created the simplest of scripts to demonstrate that it does not work:
#!/bin/bash
echo -e "e[1;31m This is red text e[0m"
However, when i run it, I see no colors at all, as shown in this image. The color output of the ls command is working fine however.
macos bash shell echo
macos bash shell echo
asked Feb 28 '15 at 13:44
nycyniknycynik
5,21454572
5,21454572
take a look at this, which I answered your question there: stackoverflow.com/a/48216286/3782119
– SHi ON
Jan 13 '18 at 23:39
I was happy to know that bash was old, and updating it solved my problem.
– nycynik
Jan 17 '18 at 13:58
add a comment |
take a look at this, which I answered your question there: stackoverflow.com/a/48216286/3782119
– SHi ON
Jan 13 '18 at 23:39
I was happy to know that bash was old, and updating it solved my problem.
– nycynik
Jan 17 '18 at 13:58
take a look at this, which I answered your question there: stackoverflow.com/a/48216286/3782119
– SHi ON
Jan 13 '18 at 23:39
take a look at this, which I answered your question there: stackoverflow.com/a/48216286/3782119
– SHi ON
Jan 13 '18 at 23:39
I was happy to know that bash was old, and updating it solved my problem.
– nycynik
Jan 17 '18 at 13:58
I was happy to know that bash was old, and updating it solved my problem.
– nycynik
Jan 17 '18 at 13:58
add a comment |
4 Answers
4
active
oldest
votes
OSX ships with an old version of Bash that does not support the e
escape character. Use x1B
or update Bash (brew install bash
).
Even better, though, would be to use tput
.
Thanks! Found a better bash after installing brew at brew.sh
– nycynik
Feb 28 '15 at 13:58
/usr/local/bin/bash --version
yields GNU bash, version 4.4.23(1)-release (x86_64-apple-darwin17.5.0) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <gnu.org/licenses/gpl.html>
– nycynik
Dec 16 '18 at 2:11
@nycynik The shipped version of bash was different 46 months before your comment; it was still on 3.x.
– danemacmillan
Jan 10 at 15:00
My second comment was the version of bash output after upgrading it .
– nycynik
Jan 14 at 1:10
add a comment |
Use 33
or x1B
instead of e
to represent de <Esc>
character.
echo -e "33[1;31m This is red text 33[0m"
See http://misc.flogisoft.com/bash/tip_colors_and_formatting
Thanks for hte link
– nycynik
May 22 '16 at 15:31
add a comment |
Another option could be using zsh, which respects the e
notation.
#!/bin/zsh
add a comment |
In script files printf
could be yet another option, you have to add trailing "n"
though.
#!/bin/bash
echo -e "e[31mOutput as is.e[m"
printf "e[32mThis is green line.e[mn"
printf "e[33;1m%sn" 'This is yellow bold line.'
Tested on macOS High Sierra 10.13.6:
% /bin/bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)
Copyright (C) 2007 Free Software Foundation, Inc.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28782394%2fhow-to-get-osx-shell-script-to-show-colors-in-echo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
OSX ships with an old version of Bash that does not support the e
escape character. Use x1B
or update Bash (brew install bash
).
Even better, though, would be to use tput
.
Thanks! Found a better bash after installing brew at brew.sh
– nycynik
Feb 28 '15 at 13:58
/usr/local/bin/bash --version
yields GNU bash, version 4.4.23(1)-release (x86_64-apple-darwin17.5.0) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <gnu.org/licenses/gpl.html>
– nycynik
Dec 16 '18 at 2:11
@nycynik The shipped version of bash was different 46 months before your comment; it was still on 3.x.
– danemacmillan
Jan 10 at 15:00
My second comment was the version of bash output after upgrading it .
– nycynik
Jan 14 at 1:10
add a comment |
OSX ships with an old version of Bash that does not support the e
escape character. Use x1B
or update Bash (brew install bash
).
Even better, though, would be to use tput
.
Thanks! Found a better bash after installing brew at brew.sh
– nycynik
Feb 28 '15 at 13:58
/usr/local/bin/bash --version
yields GNU bash, version 4.4.23(1)-release (x86_64-apple-darwin17.5.0) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <gnu.org/licenses/gpl.html>
– nycynik
Dec 16 '18 at 2:11
@nycynik The shipped version of bash was different 46 months before your comment; it was still on 3.x.
– danemacmillan
Jan 10 at 15:00
My second comment was the version of bash output after upgrading it .
– nycynik
Jan 14 at 1:10
add a comment |
OSX ships with an old version of Bash that does not support the e
escape character. Use x1B
or update Bash (brew install bash
).
Even better, though, would be to use tput
.
OSX ships with an old version of Bash that does not support the e
escape character. Use x1B
or update Bash (brew install bash
).
Even better, though, would be to use tput
.
answered Feb 28 '15 at 13:51
danemacmillandanemacmillan
881912
881912
Thanks! Found a better bash after installing brew at brew.sh
– nycynik
Feb 28 '15 at 13:58
/usr/local/bin/bash --version
yields GNU bash, version 4.4.23(1)-release (x86_64-apple-darwin17.5.0) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <gnu.org/licenses/gpl.html>
– nycynik
Dec 16 '18 at 2:11
@nycynik The shipped version of bash was different 46 months before your comment; it was still on 3.x.
– danemacmillan
Jan 10 at 15:00
My second comment was the version of bash output after upgrading it .
– nycynik
Jan 14 at 1:10
add a comment |
Thanks! Found a better bash after installing brew at brew.sh
– nycynik
Feb 28 '15 at 13:58
/usr/local/bin/bash --version
yields GNU bash, version 4.4.23(1)-release (x86_64-apple-darwin17.5.0) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <gnu.org/licenses/gpl.html>
– nycynik
Dec 16 '18 at 2:11
@nycynik The shipped version of bash was different 46 months before your comment; it was still on 3.x.
– danemacmillan
Jan 10 at 15:00
My second comment was the version of bash output after upgrading it .
– nycynik
Jan 14 at 1:10
Thanks! Found a better bash after installing brew at brew.sh
– nycynik
Feb 28 '15 at 13:58
Thanks! Found a better bash after installing brew at brew.sh
– nycynik
Feb 28 '15 at 13:58
/usr/local/bin/bash --version
yields GNU bash, version 4.4.23(1)-release (x86_64-apple-darwin17.5.0) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <gnu.org/licenses/gpl.html>– nycynik
Dec 16 '18 at 2:11
/usr/local/bin/bash --version
yields GNU bash, version 4.4.23(1)-release (x86_64-apple-darwin17.5.0) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <gnu.org/licenses/gpl.html>– nycynik
Dec 16 '18 at 2:11
@nycynik The shipped version of bash was different 46 months before your comment; it was still on 3.x.
– danemacmillan
Jan 10 at 15:00
@nycynik The shipped version of bash was different 46 months before your comment; it was still on 3.x.
– danemacmillan
Jan 10 at 15:00
My second comment was the version of bash output after upgrading it .
– nycynik
Jan 14 at 1:10
My second comment was the version of bash output after upgrading it .
– nycynik
Jan 14 at 1:10
add a comment |
Use 33
or x1B
instead of e
to represent de <Esc>
character.
echo -e "33[1;31m This is red text 33[0m"
See http://misc.flogisoft.com/bash/tip_colors_and_formatting
Thanks for hte link
– nycynik
May 22 '16 at 15:31
add a comment |
Use 33
or x1B
instead of e
to represent de <Esc>
character.
echo -e "33[1;31m This is red text 33[0m"
See http://misc.flogisoft.com/bash/tip_colors_and_formatting
Thanks for hte link
– nycynik
May 22 '16 at 15:31
add a comment |
Use 33
or x1B
instead of e
to represent de <Esc>
character.
echo -e "33[1;31m This is red text 33[0m"
See http://misc.flogisoft.com/bash/tip_colors_and_formatting
Use 33
or x1B
instead of e
to represent de <Esc>
character.
echo -e "33[1;31m This is red text 33[0m"
See http://misc.flogisoft.com/bash/tip_colors_and_formatting
answered May 21 '16 at 17:35
guapologuapolo
1,39511316
1,39511316
Thanks for hte link
– nycynik
May 22 '16 at 15:31
add a comment |
Thanks for hte link
– nycynik
May 22 '16 at 15:31
Thanks for hte link
– nycynik
May 22 '16 at 15:31
Thanks for hte link
– nycynik
May 22 '16 at 15:31
add a comment |
Another option could be using zsh, which respects the e
notation.
#!/bin/zsh
add a comment |
Another option could be using zsh, which respects the e
notation.
#!/bin/zsh
add a comment |
Another option could be using zsh, which respects the e
notation.
#!/bin/zsh
Another option could be using zsh, which respects the e
notation.
#!/bin/zsh
answered Feb 1 '16 at 17:03
Adam MatanAdam Matan
50k93264419
50k93264419
add a comment |
add a comment |
In script files printf
could be yet another option, you have to add trailing "n"
though.
#!/bin/bash
echo -e "e[31mOutput as is.e[m"
printf "e[32mThis is green line.e[mn"
printf "e[33;1m%sn" 'This is yellow bold line.'
Tested on macOS High Sierra 10.13.6:
% /bin/bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)
Copyright (C) 2007 Free Software Foundation, Inc.
add a comment |
In script files printf
could be yet another option, you have to add trailing "n"
though.
#!/bin/bash
echo -e "e[31mOutput as is.e[m"
printf "e[32mThis is green line.e[mn"
printf "e[33;1m%sn" 'This is yellow bold line.'
Tested on macOS High Sierra 10.13.6:
% /bin/bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)
Copyright (C) 2007 Free Software Foundation, Inc.
add a comment |
In script files printf
could be yet another option, you have to add trailing "n"
though.
#!/bin/bash
echo -e "e[31mOutput as is.e[m"
printf "e[32mThis is green line.e[mn"
printf "e[33;1m%sn" 'This is yellow bold line.'
Tested on macOS High Sierra 10.13.6:
% /bin/bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)
Copyright (C) 2007 Free Software Foundation, Inc.
In script files printf
could be yet another option, you have to add trailing "n"
though.
#!/bin/bash
echo -e "e[31mOutput as is.e[m"
printf "e[32mThis is green line.e[mn"
printf "e[33;1m%sn" 'This is yellow bold line.'
Tested on macOS High Sierra 10.13.6:
% /bin/bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)
Copyright (C) 2007 Free Software Foundation, Inc.
answered Nov 19 '18 at 13:17
cu39cu39
1112
1112
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28782394%2fhow-to-get-osx-shell-script-to-show-colors-in-echo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
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
take a look at this, which I answered your question there: stackoverflow.com/a/48216286/3782119
– SHi ON
Jan 13 '18 at 23:39
I was happy to know that bash was old, and updating it solved my problem.
– nycynik
Jan 17 '18 at 13:58