From: Matthijs Kooijman Date: Wed, 7 Jan 2009 20:56:18 +0000 (+0100) Subject: Add starts_with function. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=ac915b2a77c0bcbcacc8b07042c7d3d2eeebb79a;p=matthijs%2Fupstream%2Fbackupninja.git Add starts_with function. This function compares two strings (paths) and checks if the first starts with the second (the first path lies within the second). --- diff --git a/lib/tools.in b/lib/tools.in index fe7d54a..b180950 100644 --- a/lib/tools.in +++ b/lib/tools.in @@ -89,3 +89,11 @@ 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" ] +}