Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Individually Execute All Files in a Directory

Tags:

bash

macos

awk

I've been trying to write a shell script to travel a directory tree and play every mp3 file it finds. afplay is my utility of choice, given that I am on a mac. However, afplay only takes one argument at a time, so you have to call it over and over again if you want it to keep playing. It seems like the simplest solution would be as follows:

$(`find . -name *.mp3 | awk '{ print "afplay \047" $0 "\047"; }' | tr '\n' ';' | sed 's/;/; /g'`)

...but something keeps getting caught up in the escaping of quotes. For quick reference, \047 is octal for ' (the single quote character), which should encapsulate arguments into one, but for some reason it is not. I have no clue what is going wrong here.


1 Answers

Why not just find . -name '*.mp3' -exec afplay '{}' \;?

like image 88
Alex Martelli Avatar answered Mar 18 '26 17:03

Alex Martelli