From: Harald Hoyer Date: Wed, 25 May 2016 12:49:34 +0000 (+0200) Subject: dracut-functions.sh: add str_starts() and str_ends() X-Git-Tag: 033-502~107 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6656e1547f875253d1499bcd06ae0f6440a087c6;p=thirdparty%2Fdracut.git dracut-functions.sh: add str_starts() and str_ends() --- diff --git a/dracut-functions.sh b/dracut-functions.sh index d71ff6768..4a9729c77 100755 --- a/dracut-functions.sh +++ b/dracut-functions.sh @@ -29,6 +29,10 @@ fi # Generic substring function. If $2 is in $1, return 0. strstr() { [[ $1 = *$2* ]]; } +# returns OK if $1 contains literal string $2 at the beginning, and isn't empty +str_starts() { [ "${1#"$2"*}" != "$1" ]; } +# returns OK if $1 contains literal string $2 at the end, and isn't empty +str_ends() { [ "${1%*"$2"}" != "$1" ]; } # helper function for check() in module-setup.sh # to check for required installed binaries