Skip to content

Instantly share code, notes, and snippets.

@narusemotoki
Created February 14, 2013 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save narusemotoki/4951328 to your computer and use it in GitHub Desktop.
Save narusemotoki/4951328 to your computer and use it in GitHub Desktop.
dirに入ったパスのファイルをランダムに一個出力します。
#!/bin/sh
dir='/home/motoki/Documents'
file_count=`ls ${dir} | wc -l`
random=`od -vAn -N4 -tu4 < /dev/random`
rnum=$(( ${random} % $file_count ))
count=0
for f in `ls ${dir}`; do
if [ "${rnum}" -eq "${count}" ]; then
file=$f
fi
count=`expr ${count} + 1`
done
echo $file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment