Skip to content

Instantly share code, notes, and snippets.

@rmlrml
Forked from scarlson/playlist.sh
Last active April 9, 2024 10:15
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rmlrml/c8147c8a697d58bba2f252dd0fc3b0db to your computer and use it in GitHub Desktop.
Save rmlrml/c8147c8a697d58bba2f252dd0fc3b0db to your computer and use it in GitHub Desktop.
Bash script to create .m3u playlist files for all mp3s in subdirectories
#!/bin/bash
#
# bash script to create playlist files in music subdirectories
#
# Steve Carlson (stevengcarlson@gmail.com)
find . -type d |
while read -r subdir
do
rm -f "$subdir"/*.m3u
for filename in "$subdir"/*
do
if [ "${filename: -4}" == ".mp3" ] || [ "${filename: -5}" == ".flac" ] || [ "${filename: -5}" == ".loss" ] || [ "${filename: -5}" == ".aiff" ] || [ "${filename: -4}" == ".aif" ]
then
echo "${filename##*/}" >> ./"$subdir"/"${subdir##*/}.m3u"
fi
done
done
@rmlrml
Copy link
Author

rmlrml commented Mar 31, 2019

line 8, read without -r will mangle backslashes

line 13, Double quote to prevent globbing and word splitting, should fix
playlist.sh: line 13: [: too many arguments

@n2j3
Copy link

n2j3 commented Nov 6, 2019

Perfect. Just what I needed

@ShibitoBrain
Copy link

I still get "playlist.sh: 13 playlist.sh: Bad substitution" error on RaspianOS with NTFS drives. Have no idea why. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment