What is the best way to choose a random file from a directory in a shell script?
Here is my solution in Bash but I would be very interested for a more portable (non-
Newlines in file-names can be avoided by doing the following in Bash:
#!/bin/sh OLDIFS=$IFS IFS=$(echo -en "\n\b") DIR="/home/user" for file in $(ls -1 $DIR) do echo $file done IFS=$OLDIFS