[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [semi-OT] How to echo \\ in dash



On Friday 28 August 2009 15:54:50 Johannes Wiedersich wrote:
> 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?
>
> It's a bit confusing that one cannot echo two \\ to another file.
>
> 15:46:25-johannes@e13-v21:~$ dash
> $ echo \\
> \
> $ echo \\\\
> \
>
> 15:46:25-johannes@e13-v21:~$ bash
> ech15:46:29-johannes@e13-v21:~$ echo \\\\
> \\
> 15:46:32-johannes@e13-v21:~$ echo \\
> \

That happens because the arguments are subject to command expansion 
before there are given to the echo command and are then interpreted 
there again. Which means, that \\\\ would be the correct way to specify 
a single \. Just try echo \\n and echo \\\\n.

Now why does behave bash differently? Easy, because echo in dash always 
does what echo -e does in bash. Maybe you should use printf instead.


Reply to: