dotfiles/bin/randfile
Agnosto Dvonik 71b5fe9977 init
2022-10-01 18:16:21 -04:00

28 lines
424 B
Bash
Executable File

#!/bin/ksh
#
# dvonik's random file grabber
#
# in public domain
#
# randomise files
randomise() {
count=1
for i in $(find "$1" 2> "/dev/null"); do
arr[$count]="$i"
count="$(( count + 1 ))"
done
size="${#arr[@]}"
index="$(( RANDOM % size ))"
echo "${arr[$index]}"
}
[ ! -e "$1" ] && {
echo "$0: $1: no such file or directory" > "/dev/stderr"
exit 1
}
randomise "$1"