dotfiles/.local/bin/randfile

28 lines
424 B
Plaintext
Raw Normal View History

2022-10-02 00:16:21 +02:00
#!/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"