Re: [PATCH v3 0/4] Changed path filter hash fix and version bump

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

 



Jonathan Tan <jonathantanmy@xxxxxxxxxx> writes:

>> + - In 'printf' format string, do not use hexadecimals, as they are not
>> +   portable.  Write 
>> +
>> +     CENT=$(printf "\302\242")
>> +
>> +   not
>> +
>> +     CENT=$(printf "\xc2\xa2")
>
> I've checked with "dash" and this applies to any quoted string, not just
> when passed to printf. I'll prepare a patch describing this.

What do you mean by "any quoted string"?

I think built-in 'echo' of dash takes "\302\242" and emits the
cent-sign (but /bin/echo may not), but I do not think it is "any
quoted string".  To wit:

    dash$ echo '\302\242'
    ¢

The echo built into dash shows the cent-sign.  The example does not
let us tell if is the shell (i.e. the 'echo' command sees the
cent-sign in its argv[1]) or if it is the command (i.e. the 'echo'
sees 8-byte string "bs three zero two bs two four two" in its
argv[1], and shows that as the cent-sign), though.

    dash$ /bin/echo '\302\242'
    \302\242

This shows that shell is not doing anything fancy.  /bin/echo gets
the 8-byte string in its argv[1] and emits that as-is.

    dash$ /bin/echo "\302\242"
    \302\242

Again this shows the same; I added this example to demonstrate that
it is _not_ like the shell interprets the backslashed octal strings
depending on how they are quoted.

    dash$ printf "%s\n" '\302\242'
    \302\242
    dash$ printf "%s\n" "\302\242"
    \302\242

And these demonstrates that argv[2] given to printf in these cases
are 8-byte string "bs three zero two bs two four two" and the shell
is not doing anything fancy.

So, I would suggest not saying "any quoted string".  In addition,
even though dash's built-in echo that recognizes "\0num" seems to be
conformant to what POSIX specifies (cf. [*1*]), GNU requires "-e" in
order to do so in both standalone 'echo' binary and one built into
'bash', so we cannot rely on this POSIX behaviour when writing a
portable script.  Hence, I would recommend us to focus on giving a
piece of advice on use of printf in this part of the documentation.


[References]

*1* https://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html
*2* https://www.gnu.org/software/coreutils/manual/html_node/echo-invocation.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux