* dash and ANSI escape sequences
@ 2014-02-18 11:54 Alex Waite
2014-02-18 13:11 ` Guido Berhoerster
2014-02-18 13:16 ` Steffen Nurpmeso
0 siblings, 2 replies; 5+ messages in thread
From: Alex Waite @ 2014-02-18 11:54 UTC (permalink / raw)
To: dash
I come here in search of someone who understands dash/portable scripting
better than I do. Today, my Google-foo is failing me.
I am in the process of cleaning up someone else's semi-portable shell
script (originally written on FreeBSD). The original script uses colors,
in the form of
echo -e "\e[1;32mpassed\e[0m"
"echo" should be avoided in general and any option passed to "echo" is
non-portable. In bash, I can easily port this to printf
printf '%b' "\x1b[32;1mpassed\x1b[0m\n"
However, this approach does not work in dash. I have read both the echo
and printf sections of the dash manual, and it seems that both "\e" and
"\x" are unsupported. Using "%b" allows additional backslash-escape
sequences, but only \c and \0.
I know the purpose of dash is to provide an efficient POSIX compliant
shell. Is there really no POSIX compliant way to use color? It seems
so... 80s. Dash's manpage does state that it supports "backslash
notation as defined in ANSI X3.159-1989 (“ANSI C89”)", but I can't find
a copy of ANSI C89 online to confirm whether it includes display
attributes. ANSI C89 is old, but still... too old for color?
Am I somehow missing some hidden functionality in printf, or is there
really no POSIX compliant method of printing colors, or is Dash simply
incomplete with its POSIX support in this regard?
Any insight is most appreciated.
---Alex
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: dash and ANSI escape sequences
2014-02-18 11:54 dash and ANSI escape sequences Alex Waite
@ 2014-02-18 13:11 ` Guido Berhoerster
2014-02-18 13:22 ` Steffen Nurpmeso
2014-02-18 13:27 ` Alex Waite
2014-02-18 13:16 ` Steffen Nurpmeso
1 sibling, 2 replies; 5+ messages in thread
From: Guido Berhoerster @ 2014-02-18 13:11 UTC (permalink / raw)
To: dash
* Alex Waite <alexqw85@gmail.com> [2014-02-18 13:10]:
> I come here in search of someone who understands dash/portable
> scripting better than I do. Today, my Google-foo is failing me.
>
> I am in the process of cleaning up someone else's semi-portable
> shell script (originally written on FreeBSD). The original script
> uses colors, in the form of
>
> echo -e "\e[1;32mpassed\e[0m"
>
> "echo" should be avoided in general and any option passed to "echo"
> is non-portable. In bash, I can easily port this to printf
>
> printf '%b' "\x1b[32;1mpassed\x1b[0m\n"
>
> However, this approach does not work in dash. I have read both the
> echo and printf sections of the dash manual, and it seems that both
> "\e" and "\x" are unsupported. Using "%b" allows additional
> backslash-escape sequences, but only \c and \0.
>
> I know the purpose of dash is to provide an efficient POSIX
> compliant shell. Is there really no POSIX compliant way to use
> color? It seems so... 80s. Dash's manpage does state that it
> supports "backslash notation as defined in ANSI X3.159-1989 (“ANSI
> C89”)", but I can't find a copy of ANSI C89 online to confirm
> whether it includes display attributes. ANSI C89 is old, but
> still... too old for color?
>
> Am I somehow missing some hidden functionality in printf, or is
> there really no POSIX compliant method of printing colors, or is
> Dash simply incomplete with its POSIX support in this regard?
dash, POSIX, or C89 have nothing to do with colors, it depends on
your terminal whether it interprets certain escape sequences as
color attributes.
You can print arbitrary bytes in a portable way (i.e. as
specified by POSIX) by using octal notation, e.g. escape is 033
in octal:
printf "\033[1;32mpassed\033[0m\n"
--
Guido Berhoerster
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: dash and ANSI escape sequences
2014-02-18 11:54 dash and ANSI escape sequences Alex Waite
2014-02-18 13:11 ` Guido Berhoerster
@ 2014-02-18 13:16 ` Steffen Nurpmeso
1 sibling, 0 replies; 5+ messages in thread
From: Steffen Nurpmeso @ 2014-02-18 13:16 UTC (permalink / raw)
To: Alex Waite; +Cc: dash
Alex Waite <alexqw85@gmail.com> wrote:
|I come here in search of someone who understands dash/portable scripting
|better than I do. Today, my Google-foo is failing me.
|
|I am in the process of cleaning up someone else's semi-portable shell
|script (originally written on FreeBSD). The original script uses colors,
|in the form of
|
|echo -e "\e[1;32mpassed\e[0m"
|
|"echo" should be avoided in general and any option passed to "echo" is
|non-portable. In bash, I can easily port this to printf
|
|printf '%b' "\x1b[32;1mpassed\x1b[0m\n"
|
|However, this approach does not work in dash. I have read both the echo
|and printf sections of the dash manual, and it seems that both "\e" and
|"\x" are unsupported. Using "%b" allows additional backslash-escape
|sequences, but only \c and \0.
|
|I know the purpose of dash is to provide an efficient POSIX compliant
|shell. Is there really no POSIX compliant way to use color? It seems
|so... 80s. Dash's manpage does state that it supports "backslash
|notation as defined in ANSI X3.159-1989 (“ANSI C89”)", but I can't find
|a copy of ANSI C89 online to confirm whether it includes display
|attributes. ANSI C89 is old, but still... too old for color?
Colours have nothing to do with the C programming language, they
are an attribute of ISO 6429/ECMA-48 capable terminals.
|Am I somehow missing some hidden functionality in printf, or is there
|really no POSIX compliant method of printing colors, or is Dash simply
|incomplete with its POSIX support in this regard?
|
|Any insight is most appreciated.
$ /usr/bin/dash -c 'printf "^[[32;1mpassed^[[0m"'
(i.e., the plain control character U+001B, ESCAPE) works for me,
also on mksh(1), ksh(1), bash(1), and old Bourne shells that
effectively go through my /usr/bin/printf.
|---Alex
--steffen
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: dash and ANSI escape sequences
2014-02-18 13:11 ` Guido Berhoerster
@ 2014-02-18 13:22 ` Steffen Nurpmeso
2014-02-18 13:27 ` Alex Waite
1 sibling, 0 replies; 5+ messages in thread
From: Steffen Nurpmeso @ 2014-02-18 13:22 UTC (permalink / raw)
To: Guido Berhoerster; +Cc: dash
Guido Berhoerster <gber@opensuse.org> wrote:
|You can print arbitrary bytes in a portable way (i.e. as
|specified by POSIX) by using octal notation, e.g. escape is 033
|in octal:
|
|printf "\033[1;32mpassed\033[0m\n"
That is of course even better.
--steffen
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: dash and ANSI escape sequences
2014-02-18 13:11 ` Guido Berhoerster
2014-02-18 13:22 ` Steffen Nurpmeso
@ 2014-02-18 13:27 ` Alex Waite
1 sibling, 0 replies; 5+ messages in thread
From: Alex Waite @ 2014-02-18 13:27 UTC (permalink / raw)
To: dash
On 02/18/2014 02:11 PM, Guido Berhoerster wrote:
>> [snip]
>> Am I somehow missing some hidden functionality in printf, or is
>> there really no POSIX compliant method of printing colors, or is
>> Dash simply incomplete with its POSIX support in this regard?
>
> dash, POSIX, or C89 have nothing to do with colors, it depends on
> your terminal whether it interprets certain escape sequences as
> color attributes.
Ahh. Ok.
> You can print arbitrary bytes in a portable way (i.e. as
> specified by POSIX) by using octal notation, e.g. escape is 033
> in octal:
>
> printf "\033[1;32mpassed\033[0m\n"
Understood; I get how this all fits together now.
Thanks for your example and explanation!
---Alex
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-02-18 13:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-18 11:54 dash and ANSI escape sequences Alex Waite
2014-02-18 13:11 ` Guido Berhoerster
2014-02-18 13:22 ` Steffen Nurpmeso
2014-02-18 13:27 ` Alex Waite
2014-02-18 13:16 ` Steffen Nurpmeso
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).