I have the following command:
$ ls -alt|head -30
which produces:
total 1891268
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Jul 24 03:03 Beenie Man - Blessed (1995) - [MP3-V0]
drwxrwxr-- 940 ikwyl6 http 69632 Jul 24 02:54 .
drwxr-xr-x 2 ikwyl6 http 4096 Jul 21 05:38 Ratatat - Magnifique (2015) [V0]
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Jul 21 03:45 The Chemical Brothers - Born in the Echoes (2015) - CD V0
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Jul 21 03:38 Wilco - Star Wars (2015) [V0]
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Jul 19 01:45 The Jon Spencer Blues Explosion - Freedom Tower - No Wave Dance Party 2015 - 2015 (WEB - MP3 - V0)
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Jun 21 17:17 Kendrick Lamar - To Pimp A Butterfly (2015) - WEB V0
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Jun 21 17:15 Atmosphere - Sad Clown Bad Dub I (1999) [MP3-192]
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Jun 21 17:15 Joel Plaskett- The Park Avenue Sobriety Test (2015) [V0]
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Jun 21 17:11 Buena Vista Social Club - 2015 - Lost And Found [V0]
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Jun 21 17:08 Florence + The Machine - How Big, How Blue, How Beautiful (Deluxe Edition) (2015) [V0]
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Jun 21 17:08 The Prodigy - The Day Is My Enemy [2015](V0)
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Jun 21 17:07 Death Cab For Cutie - Kintsugi (2015) - WEB V0
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Jun 21 17:07 Sufjan Stevens - Carrie & Lowell (2015) [V0]
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Jun 21 17:02 Aesop Rock-Cat Food -2014-V0
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Jun 21 16:59 Hot Chip - Why Make Sense (2015) [v0]
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Jun 21 16:59 Outkast- SouthernPlayalistiCadillacMuzik [V0]
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Jun 21 16:53 Beirut - No No No (Single) (2015) - WEB V0
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Jun 21 16:52 Jedi_Mind_Tricks-The_Thief_and_the_Fallen-2015-NOiR
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Jun 21 16:46 Built To Spill - Untethered Moon (2015) [v0]
drwxr-xr-x 3 root root 4096 Jun 12 22:18 ..
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Feb 3 03:23 Belle and Sebastian - Girls in Peacetime Want to Dance (2015) MP3 320
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Feb 3 03:19 Caribou - Our Love (2014) [v0]
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Feb 3 03:06 Bob Dylan - Shadows in the Night (2015) [V0]
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Jan 2 2015 The Smashing Pumpkins - Monuments to an Elegy - 2014 (WEB V0)
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Dec 26 2014 .sync-pi
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Dec 2 2014 AC-DC - Rock or Bust (2014) [V0]
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Dec 2 2014 The Decemberists_What a Terrible World, What a Beautiful World
drwxr-xr-x 2 ikwyl6 ikwyl6 4096 Nov 28 2014 Wu-Tang Clan - A Better Tomorrow (2014) - WEB V0
I want to be able to traverse into each of these directories and list the mp3s in them with added HTML. I know how to do this on a specific directory but doing this:
for I in ls Wilco\ -\ Star\ Wars\ \(2015\)\ \[V0\]/*; do echo "<li><a href=\"#\" data-src=\"music/$I\">$I</a></li>"; done
which gives and which I want to have as the end result for each line of mp3 (showing only 1 line for simplicity):
<li><a href="#" data-src="music/Wilco - Star Wars (2015) [V0]/01 - EKG.mp3">Wilco - Star Wars (2015) [V0]/01 - EKG.mp3</a></li>
As a start to see how I can obtain getting each directory as a variable for a nested for loop to print each mp3 in each directory, I have tried something like this:
for J in ls `ls -alt|head -30`; do
echo $J
done
but I run into roadblocks as the output takes each space in each directory name as a new line. Anyone have any ideas how I can do this? How can I get the directory name (which may have characters that may need to be escaped) as a variable for another loop?