4 ms·
My version: #!/bin/bash SOUNDPATH=${HOME}/.play-random/sounds if [ ! -d ${SOUNDPATH} ]; then echo "Create and populate '${SOUNDPATH}' directory"
by slug 16y ago
My version:
#!/bin/bash
SOUNDPATH=${HOME}/.play-random/sounds
if [ ! -d ${SOUNDPATH} ]; then
echo "Create and populate '${SOUNDPATH}' directory"
exit 1;
fi
SOUNDS=($(ls "${SOUNDPATH}"))
NUM_SOUNDS=${#SOUNDS[*]}
if [ ${NUM_SOUNDS} -eq 0 ]; then
echo "No sound files found in '${SOUNDPATH}' directory"
exit 1;
fi
# select which sound to play
SOUND="${SOUNDPATH}/${SOUNDS[$((RANDOM%NUM_SOUNDS))]}"
echo ${SOUND}
/usr/bin/aplay ${SOUND}
code at: http://aeminium.org/slug/software/shell/#play.random.sh http://aeminium.org/slug/software/shell/#play.random.sh
There's a way of removing that ls ${DIR} and use an echo ${DIR}/* at the expense of making it a bit uglier to detect when there's no sound files.