|
107 | 107 |
|
108 | 108 | declare -a args=() |
109 | 109 | declare -a dirs=() |
110 | | -while [ $# -gt 0 ]; do |
| 110 | +while (( $# > 0 )); do |
111 | 111 | case "$1" in |
112 | 112 | -d|--dir) |
113 | 113 | dirs=("${dirs[@]}" "$2") |
@@ -170,24 +170,24 @@ regex_mode=${regex_mode:--E} |
170 | 170 | use_absolute_path=${use_absolute_path:-false} |
171 | 171 | seperator="${seperator:-!}" |
172 | 172 |
|
173 | | -[ "${#args[@]}" -eq 0 ] && usage 1 "No find file pattern!" |
174 | | -[ "${#args[@]}" -gt 1 ] && usage 1 "More than 1 file pattern!" |
| 173 | +(( "${#args[@]}" == 0 )) && usage 1 "No find file pattern!" |
| 174 | +(( "${#args[@]}" > 1 )) && usage 1 "More than 1 file pattern: ${args[@]}" |
175 | 175 | readonly pattern="${args[0]}" |
176 | 176 |
|
177 | | -# convert dirs to Absolute Path. |
178 | | -$use_absolute_path && { |
179 | | - declare -a tmp_dirs=() |
180 | | - |
181 | | - for d in "${dirs[@]}"; do |
182 | | - tmp_dirs=( "${tmp_dirs[@]}" "$(cd "$d" && pwd)" ) |
183 | | - done |
184 | | - |
185 | | - dirs=( "${tmp_dirs[@]}" ) |
186 | | -} |
| 177 | +declare -a tmp_dirs=() |
| 178 | +for d in "${dirs[@]}"; do |
| 179 | + [ -e "$d" ] || die "file $d(specified by option -d) does not exist!" |
| 180 | + [ -d "$d" ] || die "file $d(specified by option -d) exists but is not a directory!" |
| 181 | + [ -r "$d" ] || die "directory $d(specified by option -d) exists but is not readable!" |
| 182 | + # convert dirs to Absolute Path |
| 183 | + $use_absolute_path && tmp_dirs=( "${tmp_dirs[@]}" "$(cd "$d" && pwd)" ) |
| 184 | +done |
| 185 | +# set dirs to Absolute Path |
| 186 | +$use_absolute_path && dirs=( "${tmp_dirs[@]}" ) |
187 | 187 |
|
188 | | -# convert to find -iname options |
| 188 | +# convert extensions to find -iname options |
189 | 189 | for e in "${extension[@]}"; do |
190 | | - [ 0 -eq "${#find_iname_options[@]}" ] && |
| 190 | + (( "${#find_iname_options[@]}" == 0 )) && |
191 | 191 | find_iname_options=( -iname "*.$e" ) || |
192 | 192 | find_iname_options=( "${find_iname_options[@]}" -o -iname "*.$e" ) |
193 | 193 | done |
|
0 commit comments