From db72659fda602e65fc329cd7a3b66ac1d9832e01 Mon Sep 17 00:00:00 2001 From: Ben Elliston Date: Sun, 17 Apr 2016 20:20:08 +1000 Subject: Reported by shellcheck. * runtest: Use $((..)) not `expr ..` and defensively double quote shell variables. --- runtest | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'runtest') diff --git a/runtest b/runtest index 15fbea2..103108d 100755 --- a/runtest +++ b/runtest @@ -25,7 +25,7 @@ # Get the execution path to this script and the current directory. mypath=${0-.} -if expr ${mypath} : '.*/.*' > /dev/null +if expr "$mypath" : '.*/.*' > /dev/null then : else @@ -33,21 +33,21 @@ else for dir in $PATH do test -z "$dir" && dir=. - if test -x $dir/$mypath + if test -x "$dir/$mypath" then - mypath=$dir/$mypath + mypath="$dir/$mypath" break fi done IFS="$save_ifs" fi -execpath=`echo ${mypath} | sed -e 's@/[^/]*$@@'` +execpath=$(echo "$mypath" | sed -e 's@/[^/]*$@@') # Get the name by which runtest was invoked and extract the config # triplet. -runtest=`echo ${mypath} | sed -e 's@^.*/@@'` -target=`echo $runtest | sed -e 's/-runtest$//'` +runtest=$(echo "$mypath" | sed -e 's@^.*/@@') +target=$(echo "$runtest" | sed -e 's/-runtest$//') if [ "$target" != runtest ] ; then target="--target ${target}" else @@ -94,7 +94,7 @@ for a in "$@" ; do done if expr $verbose \> 0 > /dev/null ; then - echo Expect binary is $expectbin + echo Expect binary is "$expectbin" fi # Find runtest.exp. First we look in its installed location, @@ -109,14 +109,19 @@ fi # # .. which is a very weak assumption -for i in `echo ${execpath} | sed -e 's@/[^/]*$@/share/dejagnu@'` `echo ${execpath} | sed -e 's@/[^/]*/[^/]*$@/share/dejagnu@'` $execpath /usr/share/dejagnu /usr/local/share/dejagnu ; do - if expr $verbose \> 1 > /dev/null ; then - echo Looking for $i/runtest.exp. +for i in \ + $(echo "$execpath" | sed -e 's@/[^/]*$@/share/dejagnu@') \ + $(echo "$execpath" | sed -e 's@/[^/]*/[^/]*$@/share/dejagnu@') \ + $execpath \ + /usr/share/dejagnu \ + /usr/local/share/dejagnu ; do + if expr "$verbose" \> 1 > /dev/null ; then + echo Looking for "$i"/runtest.exp. fi - if [ -f $i/runtest.exp ] ; then + if [ -f "$i/runtest.exp" ] ; then runpath=$i - if expr $verbose \> 0 > /dev/null ; then - echo Using $i/runtest.exp as main test driver + if expr "$verbose" \> 0 > /dev/null ; then + echo Using "$i"/runtest.exp as main test driver fi break fi @@ -126,8 +131,8 @@ done if [ x"$DEJAGNULIBS" != x ] ; then runpath=$DEJAGNULIBS - if expr $verbose \> 0 > /dev/null ; then - echo Using $DEJAGNULIBS/runtest.exp as main test driver + if expr "$verbose" \> 0 > /dev/null ; then + echo Using "$DEJAGNULIBS"/runtest.exp as main test driver fi fi if [ x"$runpath" = x ] ; then @@ -135,9 +140,9 @@ if [ x"$runpath" = x ] ; then exit 1 fi -if ! type $expectbin >/dev/null 2>/dev/null ; then - echo "ERROR: unable to find expect on the PATH" +if ! type "$expectbin" > /dev/null 2> /dev/null ; then + echo "ERROR: unable to find expect in the PATH" exit 1 fi -exec $expectbin $debug -- $runpath/runtest.exp $target ${1+"$@"} +exec "$expectbin" "$debug" -- "$runpath/runtest.exp" "$target" ${1+"$@"} -- cgit v1.1