forked from part-cw/lambdanative
-
Notifications
You must be signed in to change notification settings - Fork 0
/
locate.sh
51 lines (46 loc) · 868 Bytes
/
locate.sh
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# locate files and directories
locatetest()
{
here=`pwd`
file=
dirs=$(echo "$SYS_PATH" | tr ":" "\n")
for dir in $dirs; do
tmp="$dir/$2"
if [ ! "X$tmp" = "X" ]; then
if [ $1 $tmp ]; then
if [ "X$file" = "X" ]; then
file=$tmp
else
if [ ! "X$3" = "Xsilent" ] && [ ! "X$file" = "X$tmp" ]; then
echo "WARNING: $file shadows $tmp" 1>&2
fi
fi
fi
fi
done
if [ "X$file" = "X" ]; then
if [ ! "X$3" = "Xsilent" ]; then
echo "WARNING: [$2] not found" 1>&2
fi
fi
if [ ! -e $file ]; then
if [ ! "X$3" = "Xsilent" ]; then
echo "WARNING: [$2] not found" 1>&2
fi
fi
cd "$here"
echo $file
}
locatedir()
{
locatetest "-d" $@
}
locatefile()
{
locatetest "-f" $@
}
wildcard_dir()
{
find $1 -maxdepth 0 -print |sort -r| head -n 1
}
#eof