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

From: Eric Lesh <[email-masked]>
Date: Thu, 09 Aug 2007 02:01:08 -0700

David Kastrup <[email-masked]> writes:

>>>> +	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.
>

There shouldn't be multiline options passed to this function, so it
might not be a problem.

> 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.
>

Heh, as you may have noticed, I'm no shell programmer :-)  Thanks for
the advice though.

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

Nice.

>>> 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.

Yeah.  That one made itself clear.  The sed -i needs to go too, as
Thomas observed.  The regexp itself also needs cleansing.

Lots of work to do...

	Eric