-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
I needed that at some point and ended up not using it, but it could be useful in bashkit
it can be made to work with all strings by removing all lines with a '/' in them
longest_common_prefix() {
__="$1"
shift 1
if (( $# == 0 )); then return; fi
local i=0
while (( $# > 0 )); do
for ((i=0; i<${#__}; i++)); do
if [[ "${__:i:1}" != "${1:i:1}" ]]; then
__=${__:0:i}
fi
done
if [[ "${1:i:1}" == "/" ]]; then
__="${__}/" # common path in arg list
fi
shift 1
done
__=${__%/*} # cut to the last /
}
Metadata
Metadata
Assignees
Labels
No labels