Re: [GUILT PATCH 2/5] guilt-guard: Assign guards to patches in series

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

 



Eric Lesh <eclesh@xxxxxxxx> writes:

> [ I'm finally back to this.  Thanks for your comments. ]
>
> Josef Sipek <jsipek@xxxxxxxxxxxxxxxxx> writes:
>
> [...]
>
>>> +}
>>> +
>>> +# usage: set_guards <patch> <guards...>
>>> +set_guards()
>>> +{
>>> +	p="$1"
>>
>> Again, be careful about namespace polution.
>>
>
> Can I use "local", or is it a bashism?  If not, use parentheses around
> the function body?
>
>>> +	shift
>>> +	for x in "$@"; do
>>> +		if [ -z $(printf %s "$x" | grep -e "^[+-]") ]; then
>>> +			echo "'$x' is not a valid guard name"
>>> +		else
>>> +			sed -i -e "s,^\($p[[:space:]]*.*\)$,\1 #$x," "$series"
>>
>> Out of curiosity, why printf and not echo?
>>
>
> For guards named '-e' or other funky things echo doesn't like and
> can't process with echo --.

The problem with the above is that it reacts strangely to multiline
options.

Should be much better (and faster on shells without builtin printf) to
use

case "$x" in
   [+-]*)
     sed -i -e ...  ;;
       *)
     echo "'$x' is not ...
esac

and this runs portably without forking on shells that are 30 years
old.  Shell script programmers _really_ should know "case" inside out.

Also, instead of 'for x in "$@"' one can just write "for x'

>> The regexp is in double quotes, so you should escape the $ (EOL),
>> as well as all the \. Yep, this is shell scripting at its worst.

\ does not need to be escaped in double quotes except before \, $ and `.
You can write

    sed -i -e "s,^\($p[[:space:]]*.*\)\$,\1 #$x," "$series"

and that's fine.

-- 
David Kastrup

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.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