]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: fix ts_option helpers
authorRuediger Meier <ruediger.meier@ga-group.nl>
Wed, 17 Feb 2016 14:01:21 +0000 (15:01 +0100)
committerRuediger Meier <ruediger.meier@ga-group.nl>
Thu, 18 Feb 2016 11:53:48 +0000 (12:53 +0100)
These two problems should be fixed now:
  - BSD awk only accepts 1-char field seperator
  - ts_has_option() did not returned "yes" if an option was given
    multiple times

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
tests/functions.sh

index d3367e1a5363bc886d05fbe13aedba309063f5b3..e639e73628fd42f59ad06a2051fc3d899f52bff9 100644 (file)
@@ -158,13 +158,15 @@ function ts_has_option {
        fi
 
        # or just check the global command line options
-       echo -n $ALL | sed 's/ //g' | awk 'BEGIN { FS="="; RS="--" } /('$NAME'$|'$NAME'=)/ { print "yes" }'
+       if [[ $ALL =~ ([$' \t\n']|^)--$NAME([$'= \t\n']|$) ]]; then echo yes; fi
 }
 
 function ts_option_argument {
        NAME="$1"
        ALL="$2"
-       echo -n $ALL | sed 's/ //g' | awk 'BEGIN { FS="="; RS="--" } /'$NAME'=/ { print $2 }'
+
+       # last option wins!
+       echo "$ALL" | sed -n "s/.*[ \t\n]--$NAME=\([^ \t\n]*\).*/\1/p" | tail -n 1
 }
 
 function ts_init_core_env {