0

I am trying to play a random .wav file from the command line. The files are called 1.wav, 2.wav, .... 10.wav

I have created the following .sh script and given it the appropriate execution rights:

#!/bin/sh
rnd=$((1 + RANDOM % 10))
cmd="aplay -D default:CARD=Device ./$rnd.wav"
echo $cmd

and it always returns

aplay -D default:CARD=Device ./1.wav

What am I missing? Thanks for your help!

Cyrus
  • 84,225
  • 14
  • 89
  • 153
ChrisB
  • 2,018
  • 2
  • 19
  • 24
  • 2
    [Can't replicate](https://repl.it/@kamilcukrowski/SpicySandyUtilities). Works fine. Maybe the shell doesn't support `RANDOM`? Change `/bin/sh` to `/bin/bash` and make sure you run bash. Try `echo $BASH_VERSION` from within the script. – KamilCuk Jun 25 '19 at 15:59
  • @KamilCuk thanks, `/bin/bash` was the problem! Brilliant! – ChrisB Jun 26 '19 at 11:21

0 Answers0