[Pm-utils] various errors in pm/functions

Peter Jones pjones at redhat.com
Tue Oct 10 09:13:58 PDT 2006


On Tue, 2006-10-10 at 13:36 +0100, Richard Hughes wrote:

> > -	files="/etc/pm/hooks/*"
> > +	files="/etc/pm/hooks/*[^~]"
> >  	if [ "$2" = "reverse" ]; then
> > -		files=$(echo $files | awk '{ for (i=NF; i>=1; i--) if ($i !~ /~$/ { print $i } }')
> > +		filea=($files)
> > +		filen=${#filea[*]}
> > +		files=""
> > +		while [ $filen -gt 0 ]; do
> > +			let filen--
> > +			files="$files ${filea[$filen]}"
> > +		done
> >  	fi
> >  	for file in $files ; do
> >  		[ -x $file ] && $file $1
> > 
> > -------
> > (actually, the awk is just missing a ")" after "if ($i !~ /~$/) {...", but
> > this "if" is totally unneeded by adjusting the glob pattern, and it probably
> > is cheaper to reverse the files in bash than forking off awk, i did it in
> > bash).

Actually, I'm committing this, instead:

@@ -62,13 +62,19 @@ run_hooks()
        [ -f /var/run/pm-suspend ] && . /var/run/pm-suspend
        rm -f /var/run/pm-suspend
 
-       files="/etc/pm/hooks/*"
+       files="/etc/pm/hooks/*[^~]"
        if [ "$2" = "reverse" ]; then
-               files=$(echo $files | awk '{ for (i=NF; i>=1; i--) if ($i !~ /~$/ { print $i } }')
+               filea=($files)
+               filen=${#filea[*]}
+               while [ "$filen" -gt 0 ]; do
+                       file="${filea[$filen]}"
+                       [ -x $file ] && $file $1
+               done
+       else
+               for file in $files ; do
+                       [ -x $file ] && $file $1
+               done
        fi
-       for file in $files ; do
-               [ -x $file ] && $file $1
-       done
 }
 
 get_power_status()

-- 
  Peter



More information about the Pm-utils mailing list