qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v2] checkpatch: add a little script to run check


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v2] checkpatch: add a little script to run checkpatch against a git refspec
Date: Tue, 22 Jan 2013 08:31:50 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2

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

[Prev in Thread] Current Thread [Next in Thread]