28 lines
424 B
Bash
Executable File
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"
|