I have the following command:
somethingRegex | xargs -I {} sh -c 'echo -e "found \e[34m{}\e[39m";dummy {}'
The color part of the echo does not work, example output:
-e found \e[34mresult\e[39m
dummy output
repeat
A plain echo does work with {} being nice blue
echo -e "found \e[34m{}\e[39m"
How do I fix this?
Perhaps this is for Linux (although OSX adds an interesting twist by reversing the roles of
bashandecho).Linux's
/bin/echohas a-eoption which expands escapes of the sort you show, while some shells (such asdash, used in Debian) follow POSIX more closely, and do not do this. Thefindprogram acts as if it runs/bin/sh, which may not be your actual shell. Debian usesdashas/bin/sh.Likewise, older versions of bash (my local OSX server has 3.2.53) do not support the
-eoption, while newer ones (checking my local Debian with 4.1.5) do support the-eoption.Since all of that behavior is non-standard, the usual recommendation is to use the
printfutility, which also provides non-standard features on Linux, but the parts that you need will be portable enough: