On Friday 28 August 2009 08:54:50 Johannes Wiedersich wrote:
> Hi list!
>
> In an effort to write my scripts in a posix conform way, I try to use
> dash instead of bash. One issue I don't understand:
>
> Why does 'echo \\\\' behave different for bash and dash?
Per the POSIX and SUS specifications, the echo command, which maybe be built
into the shell, may apply C-sytle escapes ("\\", "\t", "\n", etc.) to the
string it receives from the shell.
Typing 'echo \\\\' at the command line or in a script sends the argv = {
"echo", "\\" } to the echo binary/built-in. At that point, a POSIX/SUS
conforming echo can output either "\" followed by a newline OR "\\" followed
by a newline.
As a user/developer, it's a pain to deal with all the flexibility of
implementation that POSIX/SUS gives the "echo" command. Instead, use the
printf command which is much better specified. Just remember to end the
printf string with "\n" if you want a final newline.
--
Boyd Stephen Smith Jr. ,= ,-_-. =.
bss@iguanasuicide.net ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-'
http://iguanasuicide.net/ \_/
Attachment:
signature.asc
Description: This is a digitally signed message part.