summaryrefslogtreecommitdiff
path: root/vsvs-locate
blob: 5015529f49454ff82dd2e5eeb6bee577c3082953 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash
# Tear $1 into path to file (or directory) and in file,
# if no such file exit with error.
after () { test -z "${2##*$1*}" && echo -n "${2#*$1}"; }
test "${1::1}" == "/" && path=$base || path="."
lastpath=$1
until test -z "$lastpath" || test -f "$path"
do
    path="$path/${lastpath%%/*}"
    lastpath=$(after / "$lastpath")
    test -e "$path" || exit 1
done
echo "$path"
echo "$lastpath"