On 01/21/2013 02:56 PM, Anthony Liguori wrote:

>>> +ret=0
>>> +git log --format="%H %s" "$@" | while read LINE; do
>>> +    commit="`echo $LINE | cut -f1 -d' '`"
>>> +    subject="`echo $LINE | cut -f2- -d' '`"
>>> +    echo "Subject: $subject"
>>
>> This won't work if $subject contains backslash.  You must use printf(1)
>> to be portable here.
> 
> What won't work, echo or read?

Both.  read without -r might interpret \ before populating $LINE; and if
\ makes it through $LINE and into $subject, then echo on any subject
containing a \ is non-portable.

>  -r should fix the read bit but echo
> doesn't interpret newlines by default.... or is that a GNU-ism?

'read -r' and 'printf' are both POSIX.  The default behavior of bash
leaving \ alone in echo is a violation of POSIX; but you can force bash
to obey POSIX with 'shopt -s xpg_echo'.  Hence, 'printf %s\\n
"$subject"' is always safer than 'echo "$subject"'.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to