From: Matthijs Kooijman Date: Wed, 7 Jan 2009 21:16:24 +0000 (+0100) Subject: Add strip_prefix function. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=1f3891846c79f57c458e6848958f4f5c5cd08898;p=matthijs%2Fupstream%2Fbackupninja.git Add strip_prefix function. This function can be used to remove a given prefix from a string. --- 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)) +}