From ac915b2a77c0bcbcacc8b07042c7d3d2eeebb79a Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Wed, 7 Jan 2009 21:56:18 +0100 Subject: [PATCH] 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). --- lib/tools.in | 8 ++++++++ 1 file changed, 8 insertions(+) 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" ] +} -- 2.30.2