Created
February 14, 2013 08:25
-
-
Save narusemotoki/4951328 to your computer and use it in GitHub Desktop.
dirに入ったパスのファイルをランダムに一個出力します。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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