Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

IOT trap -- core dumped


devel / comp.unix.shell / Re: Display color output in the script

SubjectAuthor
* Display color output in the scripthongy...@gmail.com
+* Re: Display color output in the scriptJanis Papanagnou
|`* Re: Display color output in the scripthongy...@gmail.com
| `- Re: Display color output in the scriptJanis Papanagnou
+* Re: Display color output in the scriptGrant Taylor
|`- Re: Display color output in the scriptGrant Taylor
`- Re: Display color output in the scriptEli the Bearded

1
Display color output in the script

<9e8a7ae8-bf5d-4e4d-baeb-0bd76a29ca15n@googlegroups.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4278&group=comp.unix.shell#4278

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a0c:8066:: with SMTP id 93mr21372765qva.52.1630289631954;
Sun, 29 Aug 2021 19:13:51 -0700 (PDT)
X-Received: by 2002:ae9:e407:: with SMTP id q7mr20565579qkc.55.1630289631821;
Sun, 29 Aug 2021 19:13:51 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sun, 29 Aug 2021 19:13:51 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=103.138.53.239; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 103.138.53.239
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9e8a7ae8-bf5d-4e4d-baeb-0bd76a29ca15n@googlegroups.com>
Subject: Display color output in the script
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Mon, 30 Aug 2021 02:13:51 +0000
Content-Type: text/plain; charset="UTF-8"
 by: hongy...@gmail.com - Mon, 30 Aug 2021 02:13 UTC

The following command will print red text output on terminal:

$ echo -e '\e[31mRED TEXT\e[m'
RED TEXT

But why it uses such a strange syntax, and how to understand/remember it conveniently?

Regards,
HY

Re: Display color output in the script

<sghfpp$2bm$1@news-1.m-online.net>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4279&group=comp.unix.shell#4279

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Display color output in the script
Date: Mon, 30 Aug 2021 04:29:13 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 31
Message-ID: <sghfpp$2bm$1@news-1.m-online.net>
References: <9e8a7ae8-bf5d-4e4d-baeb-0bd76a29ca15n@googlegroups.com>
NNTP-Posting-Host: 2001:a61:2431:ec01:c81:4b40:212d:333a
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1630290553 2422 2001:a61:2431:ec01:c81:4b40:212d:333a (30 Aug 2021 02:29:13 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Mon, 30 Aug 2021 02:29:13 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Enigmail-Draft-Status: N1110
In-Reply-To: <9e8a7ae8-bf5d-4e4d-baeb-0bd76a29ca15n@googlegroups.com>
 by: Janis Papanagnou - Mon, 30 Aug 2021 02:29 UTC

On 30.08.2021 04:13, hongy...@gmail.com wrote:
> The following command will print red text output on terminal:
>
> $ echo -e '\e[31mRED TEXT\e[m'

This is no portable shell syntax. My Kornshell, for example, wants

echo $'\e[31mRED TEXT\e[m'
or
printf "\e[31mRED TEXT\e[m"

> RED TEXT
>
> But why it uses such a strange syntax,

The '\e' character is ESC and '[' introduces the CSI; You may find
more detailled answers for CSI (Control Sequence Introducer) here:
https://en.wikipedia.org/wiki/ANSI_escape_code

> and how to understand/remember it conveniently?

Look it up in tables (e.g. on the page linked above).

Janis

>
> Regards,
> HY
>

Re: Display color output in the script

<5724f047-fe1a-4c03-8896-eae2959c84f7n@googlegroups.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4281&group=comp.unix.shell#4281

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:620a:1aa6:: with SMTP id bl38mr20520433qkb.36.1630291342222;
Sun, 29 Aug 2021 19:42:22 -0700 (PDT)
X-Received: by 2002:ac8:71d7:: with SMTP id i23mr14691891qtp.284.1630291341997;
Sun, 29 Aug 2021 19:42:21 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sun, 29 Aug 2021 19:42:21 -0700 (PDT)
In-Reply-To: <sghfpp$2bm$1@news-1.m-online.net>
Injection-Info: google-groups.googlegroups.com; posting-host=103.138.53.245; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 103.138.53.245
References: <9e8a7ae8-bf5d-4e4d-baeb-0bd76a29ca15n@googlegroups.com> <sghfpp$2bm$1@news-1.m-online.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5724f047-fe1a-4c03-8896-eae2959c84f7n@googlegroups.com>
Subject: Re: Display color output in the script
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Mon, 30 Aug 2021 02:42:22 +0000
Content-Type: text/plain; charset="UTF-8"
 by: hongy...@gmail.com - Mon, 30 Aug 2021 02:42 UTC

On Monday, August 30, 2021 at 10:29:18 AM UTC+8, Janis Papanagnou wrote:
> On 30.08.2021 04:13, hongy...@gmail.com wrote:
> > The following command will print red text output on terminal:
> >
> > $ echo -e '\e[31mRED TEXT\e[m'
> This is no portable shell syntax. My Kornshell, for example, wants
>
> echo $'\e[31mRED TEXT\e[m'
> or
> printf "\e[31mRED TEXT\e[m"

They are all work in bash too.

> > RED TEXT
> >
> > But why it uses such a strange syntax,
> The '\e' character is ESC and '[' introduces the CSI; You may find
> more detailled answers for CSI (Control Sequence Introducer) here:
> https://en.wikipedia.org/wiki/ANSI_escape_code
> > and how to understand/remember it conveniently?
> Look it up in tables (e.g. on the page linked above).
>
> Janis
>
> >
> > Regards,
> > HY
> >

Re: Display color output in the script

<sghjmb$3fv$1@news-1.m-online.net>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4284&group=comp.unix.shell#4284

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Display color output in the script
Date: Mon, 30 Aug 2021 05:35:39 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 18
Message-ID: <sghjmb$3fv$1@news-1.m-online.net>
References: <9e8a7ae8-bf5d-4e4d-baeb-0bd76a29ca15n@googlegroups.com>
<sghfpp$2bm$1@news-1.m-online.net>
<5724f047-fe1a-4c03-8896-eae2959c84f7n@googlegroups.com>
NNTP-Posting-Host: 2001:a61:2431:ec01:c81:4b40:212d:333a
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1630294539 3583 2001:a61:2431:ec01:c81:4b40:212d:333a (30 Aug 2021 03:35:39 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Mon, 30 Aug 2021 03:35:39 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
In-Reply-To: <5724f047-fe1a-4c03-8896-eae2959c84f7n@googlegroups.com>
 by: Janis Papanagnou - Mon, 30 Aug 2021 03:35 UTC

On 30.08.2021 04:42, hongy...@gmail.com wrote:
> On Monday, August 30, 2021 at 10:29:18 AM UTC+8, Janis Papanagnou wrote:
>> On 30.08.2021 04:13, hongy...@gmail.com wrote:
>>> The following command will print red text output on terminal:
>>>
>>> $ echo -e '\e[31mRED TEXT\e[m'
>> This is no portable shell syntax. My Kornshell, for example, wants
>>
>> echo $'\e[31mRED TEXT\e[m'
>> or
>> printf "\e[31mRED TEXT\e[m"
>
> They are all work in bash too.

So better use a more widely portable form; printf is often suggested.

Janis

Re: Display color output in the script

<sghn08$bsb$1@tncsrv09.home.tnetconsulting.net>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4285&group=comp.unix.shell#4285

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!rocksolid2!i2pn.org!weretis.net!feeder6.news.weretis.net!tncsrv06.tnetconsulting.net!tncsrv09.home.tnetconsulting.net!.POSTED.alpha.home.tnetconsulting.net!not-for-mail
From: gtay...@tnetconsulting.net (Grant Taylor)
Newsgroups: comp.unix.shell
Subject: Re: Display color output in the script
Date: Sun, 29 Aug 2021 22:28:58 -0600
Organization: TNet Consulting
Message-ID: <sghn08$bsb$1@tncsrv09.home.tnetconsulting.net>
References: <9e8a7ae8-bf5d-4e4d-baeb-0bd76a29ca15n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 30 Aug 2021 04:32:08 -0000 (UTC)
Injection-Info: tncsrv09.home.tnetconsulting.net; posting-host="alpha.home.tnetconsulting.net:198.18.18.251";
logging-data="12171"; mail-complaints-to="newsmaster@tnetconsulting.net"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.9.0
In-Reply-To: <9e8a7ae8-bf5d-4e4d-baeb-0bd76a29ca15n@googlegroups.com>
Content-Language: en-US
 by: Grant Taylor - Mon, 30 Aug 2021 04:28 UTC

On 8/29/21 8:13 PM, hongy...@gmail.com wrote:
> The following command will print red text output on terminal:
>
> $ echo -e '\e[31mRED TEXT\e[m'
> RED TEXT
>
> But why it uses such a strange syntax, and how to understand/remember
> it conveniently?

It's not strange once you have a vague understanding of what's happening.

The pair of bytes <Escape> followed by <[> (0x1B and 0x5B respectively)
is what's known as the Control Sequence Introducer. The CSI tells
terminals that support it that a control sequence is immediately
following the CSI.

The 31m is a Character Attribute control sequence. (I.I. lists it as
SGR). The 31 sets the foreground to red. The m is the end of the
Character Attribute control sequence.

The "RED TEXT" is just normal text that is using the current text state,
which happens to be red.

Next the CSI Character Attribute is used to change text attributes back
to (implicit) 0 which is normal / default.

This means that you're echoing a CSI+CA to change to red, followed by
your "RED TEXT", followed by a CSI+CA to reset back to defaults.

The "-e" in the echo is how you tell (that version of) echo that "\e"
should be interpreted as escape (0x1B).

My preferred reference is invisible-island's XTerm Control Sequences
page -- https://invisible-island.net/xterm/ctlseqs/ctlseqs.html

Another very good reference is VT100's Select Graphic Rendition page --
https://vt100.net/docs/vt510-rm/SGR.html

Aside: CSI is /almost/ always <Escape>+<[>. However I have run into a
few systems / terminals that use a different CSI. One or both of the
links that I provided will talk about the pair that is used for CSI.

As for remembering this, well, once you've done it a few times, you'll
pick up on the fact that it's the <CSI><SGR>text<CSI><SGR> format.
You'll also have an idea what to look up and where to look it up.

There are a lot of things that talk about the SGR options, particularly
colors. Fewer will talk about the different things that you can do with
fonts. -- Both of the sites I linked to will talk about fonts. It's a
matter of what your terminal (emulator) supports. -- You'll find that
there are few sites that talk about more of the fancier things that you
can do. }:-) Double height and / or double width text is ... something
to behold. As are Sixel and ReGIS graphics in a text terminal. (No
Unicode pseudo graphics via Braille characters here.)

--
Grant. . . .
unix || die

Re: Display color output in the script

<sghn4e$bsb$2@tncsrv09.home.tnetconsulting.net>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4286&group=comp.unix.shell#4286

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!tncsrv06.tnetconsulting.net!tncsrv09.home.tnetconsulting.net!.POSTED.alpha.home.tnetconsulting.net!not-for-mail
From: gtay...@tnetconsulting.net (Grant Taylor)
Newsgroups: comp.unix.shell
Subject: Re: Display color output in the script
Date: Sun, 29 Aug 2021 22:31:12 -0600
Organization: TNet Consulting
Message-ID: <sghn4e$bsb$2@tncsrv09.home.tnetconsulting.net>
References: <9e8a7ae8-bf5d-4e4d-baeb-0bd76a29ca15n@googlegroups.com>
<sghn08$bsb$1@tncsrv09.home.tnetconsulting.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 30 Aug 2021 04:34:22 -0000 (UTC)
Injection-Info: tncsrv09.home.tnetconsulting.net; posting-host="alpha.home.tnetconsulting.net:198.18.18.251";
logging-data="12171"; mail-complaints-to="newsmaster@tnetconsulting.net"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.9.0
In-Reply-To: <sghn08$bsb$1@tncsrv09.home.tnetconsulting.net>
Content-Language: en-US
 by: Grant Taylor - Mon, 30 Aug 2021 04:31 UTC

On 8/29/21 10:28 PM, Grant Taylor wrote:
> There are a lot of things that talk about the SGR options, particularly
> colors.  Fewer will talk about the different things that you can do with
> fonts.  --  Both of the sites I linked to will talk about fonts.  It's a
> matter of what your terminal (emulator) supports.  --  You'll find that
> there are few sites that talk about more of the fancier things that you
> can do.  }:-)  Double height and / or double width text is ... something
> to behold.  As are Sixel and ReGIS graphics in a text terminal.  (No
> Unicode pseudo graphics via Braille characters here.)

Once you go far enough down the rabbit hole of what you can do with
control sequences, you may end up doing something like checking the
answer back from terminal (emulators) to see if it matches a configured
list to play with different capabilities. Then you can do really fancy
things like having Zsh (or maybe even Bash) display a small graphic
(again, not Unicode cheat) that is a yield / stop sign if $? of the last
command was > 0. ;-)

--
Grant. . . .
unix || die

Re: Display color output in the script

<eli$2108300033@qaz.wtf>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4287&group=comp.unix.shell#4287

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix5.panix.com!qz!not-for-mail
From: *...@eli.users.panix.com (Eli the Bearded)
Newsgroups: comp.unix.shell
Subject: Re: Display color output in the script
Date: Mon, 30 Aug 2021 04:33:30 -0000 (UTC)
Organization: Some absurd concept
Message-ID: <eli$2108300033@qaz.wtf>
References: <9e8a7ae8-bf5d-4e4d-baeb-0bd76a29ca15n@googlegroups.com>
Injection-Date: Mon, 30 Aug 2021 04:33:30 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="panix5.panix.com:166.84.1.5";
logging-data="23943"; mail-complaints-to="abuse@panix.com"
User-Agent: Vectrex rn 2.1 (beta)
X-Liz: It's actually happened, the entire Internet is a massive game of Redcode
X-Motto: "Erosion of rights never seems to reverse itself." -- kenny@panix
X-US-Congress: Moronic Fucks.
X-Attribution: EtB
XFrom: is a real address
Encrypted: double rot-13
 by: Eli the Bearded - Mon, 30 Aug 2021 04:33 UTC

In comp.unix.shell, hongy...@gmail.com <hongyi.zhao@gmail.com> wrote:
> The following command will print red text output on terminal:
>
> $ echo -e '\e[31mRED TEXT\e[m'
> RED TEXT
>
> But why it uses such a strange syntax, and how to understand/remember
> it conveniently?

I use tput commands to emit them easily / conveniently. tput looks up
the sequence from the terminal definition and substitutes variables
(when needed) then emits the escape sequence.

Use "setaf" for set ansi foreground or "setab" for set ansi background,
and a color code from 0 to 7.

red_fg=$(tput setaf 1) # red foreground
white_fg=$(tput setaf 7) # white foreground
yellow_bg=$(tput setab 3) # yellow background
black_bg=$(tput setab 0) # yellow background
revert=$(tput sgr0) # revert to defaults

echo "${red_fg}${yellow_bg}red on yellow${revert}"
echo "${white_fg}${black_bg}white on black${revert}"

Handy code cheat sheet (nothing bash specific about it):
https://cheatography.com/chrissoper1/cheat-sheets/bash-script-colors/

More information in terminfo and tput man pages.

Elijah
------
more likely to use bold or underlining than colors

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor