Thread (1 message) 1 message, 1 author, 2016-06-15

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

From: Eric Lesh <hidden>
Date: 2016-06-15 22:43:28

David Kastrup [off-list ref] writes:
quoted
quoted
quoted
+	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.
quoted
quoted
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help