-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfind_missing.sh
executable file
·64 lines (57 loc) · 1.53 KB
/
find_missing.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
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# list directories in which given find expression is not found
echo_debug() {
echo "DEBUG $@" 1>&2
}
echo_error() {
echo "ERROR: $@" 1>&2
}
debug=0
sym_link_opts=""
path=""
opts=""
while [ "$1" != "" ]; do
case $1 in
--debug )
debug=1;
;;
-H | -L | -P )
sym_link_opts="$sym_link_opts $1"
;;
-* )
# First time we encounter a dash other than -HLP means the
# rest are all expressions
expressions="$expressions $@"
break
;;
* )
if [ -d "$1" ]; then
path="$path $1"
else
echo_error "don't know how to handle $1"
fi
;;
esac
shift
done
depth_opts=""
if echo "$expressions" | grep -q -- ' -m[ai][xn]depth'; then
depth_opts=$(echo "$expressions" | sed -e 's,.* \(-m[ai][xn]depth [0-9]*\).*,\1,')
expressions=$(echo "$expressions" | sed -e 's, -m[ai][xn]depth [0-9]*,,')
fi
test -n "$path" || exit 1
test -n "$expressions" || exit 1
if [ $debug -eq 1 ]; then
#echo "DEBUG: remaing args after parsing: \$@=$@"
echo_debug "path=$path"
echo_debug "depth_opts=$depth_opts"
echo_debug "expressions=$expressions"
echo_debug "sym_link_opts=$sym_link_opts"
fi
# min/maxdepth only affects dir
for d in $(find $sym_link_opts $path $depth_opts -type d); do
test $debug -eq 1 && echo_debug "checking d=$d"
if [ $(find $sym_link_opts $d $expressions | wc -l) -eq 0 ]; then
echo $d;
fi
done