#!/bin/sh _usage () { cat</dev/null 2>&1; then echo "'realpath' not found in PATH. Exiting." >&2 exit 1 fi for i ; do ## Find over '.*' and '*', is bad practice since if will fail on ## non-existing files or for files beginning with a dash. The 'printf' ## command in find is for GNU find only. ## The two following lines do the same for the same time cost. The former is shorter. # find "$i" -type f | awk -v str="$i" '{l=length(str)+2; print substr($0, l)}' | sort > "$OUTPUT" ## 'LC_ALL=C sort' is required to make sure to output is consistent across ## different systems. (cd -- "$i" && find . -type f) | sed 's/^.\///' | LC_ALL=C sort | \ if $opt_file; then i="$(realpath -- "$i")" base="${i##*/}" [ ! -d "$i" ] && continue output="$base.index" [ -e "$OUTPUT" ] && $opt_noclobber && output="$base-$(date +%F-%T).index" echo "$output" cat > "$output" else cat fi done