From 1f3891846c79f57c458e6848958f4f5c5cd08898 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Wed, 7 Jan 2009 22:16:24 +0100 Subject: [PATCH] Add strip_prefix function. This function can be used to remove a given prefix from a string. --- lib/tools.in | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/tools.in b/lib/tools.in index b180950..4ca438f 100644 --- a/lib/tools.in +++ b/lib/tools.in @@ -97,3 +97,11 @@ function starts_with() { # 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)) +} -- 2.30.2