0

I have a bash script that goes through my music folder, gets all the song metadata with mediainfo and is intended to make folders out of all the artists' names, but it fails.

This is the code so far:

#!/bin/bash
cd Music/
for i in "$(ls -b | grep -v /)"; do
    info=$(mediainfo $i)
    artist=$(echo "$info" | grep "^Performer" | awk '{for(i=3;i<=NF;++i)printf $i""FS ; print ""}')
    mkdir "$artist"
done

For some reason, it seems to go through all the songs first and then tries to make a directory with all their names combined; my intent is to create a directory for the performer found by Mediainfo in each music file.

1

You can Iterate over files without ls.

for i in ./Music/*; do
    info=$(mediainfo "$i") # fixed to "$i"
    artist=$(echo "$info" | grep "^Performer" | awk '{for(i=3;i<=NF;++i)printf $i""FS ; print ""}')
    mkdir "$artist"
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.