Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #265620
| From | Kent West <westk@acu.edu> |
|---|---|
| Newsgroups | linux.debian.user |
| Subject | Re: OT: coloured text? |
| Date | 2024-01-07 20:10 +0100 |
| Message-ID | <HTGGZ-1vln-7@gated-at.bofh.it> (permalink) |
| References | <HTGnD-1uZv-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
[Multipart message — attachments visible in raw view] - view raw
On Sun, Jan 7, 2024 at 12:41 PM Hans <hans.ullrich@loop.de> wrote:
> Hi folks,
>
> just a short question, please allow me to ask:
>
> How can I get coloured text output in a shell script?
>
> I am using:
>
> echo "my text bla"
>
> As far as I read and understood, this is not possible in every shell. I
> found
> nothing in bash manual for example.
>
> Debian is using "dash" and not "bash", if I am correct, and with using the
> shebang line :!/bin/sh it is using dash, am I correct?
>
> If I want coloured text, which shell do I have to use and what is the
> syntax
> then within the shell script?
>
> I searched the web, but could not find a clear answer to this.
>
> Thanks for a short answer.
>
> Best regards
>
> Hans
>
>
>
"sh" is probably "/usr/bin/sh" ("$ command -v sh" or the (now-deprecated?)
"which sh" will show you which "sh" is being called), which is probably a
symlink to "dash" ("ls -lah <path>" will show that to you).
But not necessarily.
Perhaps one of the easiest ways to get color in a bash/dash/sh shell is to
use ANSI Terminal Escape Sequences. Not 100% portable, but probably
suitable for what you want.
Something like:
#!/bin/env sh
printf "\033[31m"
printf "Now we're printing in Red\n"
printf "\033[0m"
printf "Now we're printing in the system default color.\n"
--
Kent West <")))><
IT Support / Client Support
Abilene Christian University
Westing Peacefully - http://kentwest.blogspot.com
Back to linux.debian.user | Previous | Next — Previous in thread | Find similar | Unroll thread
OT: coloured text? Hans <hans.ullrich@loop.de> - 2024-01-07 19:50 +0100
Re: OT: coloured text? Greg Wooledge <greg@wooledge.org> - 2024-01-07 20:10 +0100
Re: OT: coloured text? Michael Kjörling <2695bd53d63c@ewoof.net> - 2024-01-07 20:20 +0100
Re: OT: coloured text? Michael Kjörling <2695bd53d63c@ewoof.net> - 2024-01-07 20:30 +0100
Re: OT: coloured text? Greg Wooledge <greg@wooledge.org> - 2024-01-07 21:00 +0100
Re: OT: coloured text? Greg Wooledge <greg@wooledge.org> - 2024-01-07 20:30 +0100
Re: OT: coloured text? Kent West <westk@acu.edu> - 2024-01-07 20:10 +0100
csiph-web