summaryrefslogtreecommitdiff
path: root/util/find.sh
blob: 4e0a04846abd64586e26a20ccd6e5bb5d5736797 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash

#echo 1>&2
#echo ::: find.sh "$@" 1>&2

while [[ $# -ne 0 ]]; do
    if [[ $1 == /* ]]; then
        unset found

        found=$(echo "${PKG_PATH}:" | while IFS= read -r -d : path; do
            if [[ -e ${path}$1 ]]; then
                if [[ ${found+@} ]]; then
                    echo -n ':'
                else
                    found=
                fi

                echo -n "${path}$1"
            fi
        done)

        #echo "=== ${found:=$1}" 1>&2
        echo "${found:=$1}"
    else
        echo "$1"
    fi

    shift
done

#echo 1>&2