X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=lib%2Ftools.in;h=4ca438f05e8dc17fc7d44537e66145609a0d1dc4;hb=1f3891846c79f57c458e6848958f4f5c5cd08898;hp=fe7d54a38de94fc8c7b44513e402e227314021d8;hpb=1775e74030da0071f8c49b60d076afdea06a8cd6;p=matthijs%2Fupstream%2Fbackupninja-vserver.git diff --git a/lib/tools.in b/lib/tools.in index fe7d54a..4ca438f 100644 --- a/lib/tools.in +++ b/lib/tools.in @@ -89,3 +89,19 @@ function interpolate() { # Do the actual interpolation echo $path | sed "$expr" } + +# Does the $1 start with $2 ? +function starts_with() { + # Get the head of $1 as long as $2 + head=`echo $1 | head -c ${#2}` + # Is it equal to $2? + [ "$head" = "$2" ] +} + +# Strip the prefix $2 from $1. Assumes that $1 actually starts with $1. +# The result is put on stdout. +function strip_prefix() { + # Strip the first ${#2} (the length of $2) characters from $1. + # tail -c +N means start at the Nth byte, 1-based, so we add 1. + echo $1 | tail -c +$((${#2}+1)) +}