Re: echo "\\1"?

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

 



On 07/27/2017 10:10 AM, Bosco wrote:
> That script of zziplib isn't mine, I only had to compile it once
> because it was necessary for compile other program (TeX Live).
> 
> I'm not talking about POSIX, and I don't mind what it said. I'm
> talking about the man page of dash, that said:
> 

> when \\ is reached is replaced by \.

When \\ is reached AS THE ARGUMENT to echo.

> Then, in the command
>   echo \\\\
> because \\ is reached first, then it will be replaced by '\'

No, you are demonstrating a gap in your understanding of shell quoting
rules.

echo \\\\
echo "\\\\"
echo '\\'
echo '\'"\\"

are all the same way to pass the two-character argument to echo.  That
two-character argument is a valid escape sequence, which in turn means
echo outputs a single \ character then a newline.

> character, immediately after that another \\ is reached, then it will
> be replaced by another '\' character. It turns out the ouput '\\'.

If you want two \ as output, you have to pass four characters (not two)
to echo, so your input has to be one of these (or other) valid quotings:

echo '\\\\'
echo "\\\\\\\\"
echo \\'\'"\\"\\'\'"\\"\\'\'
etc.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux