É muito mais fácil em zsh
:
for sg in ~/region/ap-*/sg-*(/); do
files=($sg/sg-*.json(N.Om)) # list of json regular files sorted
# from oldest to newest
if (($#files >= 2)); then
oldest=$files[1]
files[1]=()
for file in $files; do
cmp -s $oldest $file ||
printf '"%s" differs from "%s"\n' $file $oldest
done
fi
done
Com ksh93
ou bash
e GNU ls
, você pode traduzir isso para:
for sg in ~/region/ap-*/sg-*/; do
eval "files=($(ls --quoting-style=shell-always -rtd -- "$sg"sg-*.json))"
if ((${#files[@]} >= 2)); then
oldest=${files[1]}
files=("${files[@]:1}")
for file in "${files[@]}"; do
cmp -s "$oldest" "$file" ||
printf '"%s" differs from "%s"\n' "$file" "$oldest"
done
fi
done