Re: [semi-OT] How to echo \\ in dash
On 2009-08-28_10:02:50, Boyd Stephen Smith Jr. wrote:
> 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/ \_/
>
A few weeks ago, I asked on this list about 'bashisms', and how I
could find out what to do about any that I might have in my scripts. I
learned about some programs that purport to scan for bashisms and
report them. I ran one of them. The only thing it reported was
'source' as an alias for '.' (dot). Nothing else was flagged.
After reading this, I would say that 'echo', without option '-e' is a
bashism that should have been flagged. In my scripts, there are
multiple instances of plain 'echo'. None of them were flagged. I
wonder what else is missing ...
--
Paul E Condon
pecondon@mesanetworks.net
Reply to: