$ afplay -v 2 $(find /System/Library/Sounds -type f -maxdepth 1 | gshuf | sed -n "1p")
上記を実行すると
- /System/Library/Sounds/Basso.aiff
- /System/Library/Sounds/Blow.aiff
- /System/Library/Sounds/Bottle.aiff
- /System/Library/Sounds/Frog.aiff
- /System/Library/Sounds/Funk.aiff
- /System/Library/Sounds/Glass.aiff
- /System/Library/Sounds/Hero.aiff
- /System/Library/Sounds/Morse.aiff
- /System/Library/Sounds/Ping.aiff
- /System/Library/Sounds/Pop.aiff
- /System/Library/Sounds/Purr.aiff
- /System/Library/Sounds/Sosumi.aiff
- /System/Library/Sounds/Submarine.aiff
- /System/Library/Sounds/Tink.aiff
のいずれかがランダムで再生されます
分解する
任意の音声ファイルを再生する
$ afplay some.mp3
乱数を取得
※ gshuf を使う場合は brew install coreutils
しておくこと
$ seq 10 | gshuf
7
6
5
3
8
10
9
1
2
4
先頭1行を取得する
$ seq 10 | sed -n '1p'
1
補足
とくにShellに詳しいわけではないのでよりよいかき方があるかも