dotfiles/.local/bin/randfile
2023-05-01 18:13:35 -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"