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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to