Re: [opensuse] Colorized output, echo via xargs.



On Tuesday 13 March 2007 02:42, Sylvester Lykkehus wrote:
Hi,

Just playing around a bit with different colors in shell scripts,
I've come across a problem colorings an output parsed through xargs.

I'm sure it's just a question of escaping the string correctly.

echo -e '\E32mTest'
Prints the word Test in green.

Here you're invoking the shell's built-in echo command, which interprets
\E:

% help echo
echo: echo [-neE] [arg ...]
Output the ARGs. If -n is specified, the trailing newline is
suppressed. If the -e option is given, interpretation of the
following backslash-escaped characters is turned on:
\a alert (bell)
\b backspace
\c suppress trailing newline
\E escape character
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\num the character whose ASCII code is NUM (octal).

You can explicitly turn off the interpretation of the above
characters with the -E option.



While
echo Test > test.txt
cat test.txt | xargs -i echo -e '\E32m{}'
prints \E32mTest

In this case, you're running /bin/echo, which does not support quite the
same set of escape characters:

% man echo
...
DESCRIPTION
NOTE: your shell may have its own version of echo which will
supersede the version described here. Please refer to your
shell's documentation for details about the
options it supports.

Echo the STRING(s) to standard output.

-n do not output the trailing newline

-e enable interpretation of backslash escapes

-E disable interpretation of backslash escapes (default)

--help display this help and exit

--version
output version information and exit

If -e is in effect, the following sequences are recognized:

\0NNN the character whose ASCII code is NNN (octal)

\\ backslash

\a alert (BEL)

\b backspace

\c suppress trailing newline

\f form feed

\n new line

\r carriage return

\t horizontal tab

\v vertical tab



Any ideas ?


The above information should be enough to alliow you to correct the
problem. That and the fact that ESC (escape) is octal 33 (this
information is available via "man ascii").


Randall Schulz
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx



Relevant Pages

  • Re: How does one represent a ")" in SED
    ... but the unix utilities are more arcane: ... You use a backslash to prevent the "normal" interpretation. ... '' are regular characters. ...
    (comp.unix.shell)
  • Re: Backslash interpretation
    ... $ echo "\$" ... You have two levels of interpretation going on there. ... For the shell, things are mostly subject to parameter ... Within double quote characters, ...
    (comp.unix.shell)
  • Re: [opensuse] Basic Bash Question
    ... It was the result of the 'echo *' statement. ... Why it would interpret the *** is also just as strange. ... interpretation of the following backslash-escaped characters is ... The -E option disables the interpretation of these escape ...
    (SuSE)
  • Re: animated characters that present your powerpoint presentation
    ... Echo has nailed it. ... Microsoft PPT MVP ... Featured Presenter, PowerPoint Live 2004 ... Peedy and Robby characters are free. ...
    (microsoft.public.powerpoint)
  • Re: [opensuse] Basic Bash Question
    ... It was the result of the 'echo *' statement. ... Why it would interpret the *** is also just as strange. ... The -E option disables the interpretation of these escape ... characters, even on systems where they are interpreted by default. ...
    (SuSE)