hi
i wrote a tiny script for randomize my xmms playlist
Code:
#/bin/bash
indexToPlay=$(expr $RANDOM % $(ls /home/sammy/MP3z | wc -l));
albumToPlay=$(ls /home/sammy/MP3z | nl - | grep -e $indexToPlay -m 1 | gawk -F $indexToPlay '{ print $2 }' | cut -f 2);
#for debugging
if [ -d /home/sammy/MP3z/"$albumToPlay" ]; then
echo "PASST $albumToPlay";
else
echo "UPS $albumToPlay";
fi
xmms /home/sammy/MP3z/"$albumToPlay"
Code:
sammy@uranos sammy $ ls -l /home/sammy/MP3z
...
drwxr-xr-x 2 sammy users 4.0K May 6 2004 Bajwa And Dale Anderson - Axis One
drwxr-xr-x 2 sammy users 4.0K May 6 2004 Balance 005 - Mixed By James Holden
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Barry White - All Time Greatest Hits
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Basement Jaxx - Remedy
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Basement Jaxx - Rooty
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Beatles - Anthology - CD1
drwxr-xr-x 2 sammy games 4.0K Nov 9 20:24 Beatsteaks - Smack Smash
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Bee Gees - Best Of
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Beenie Man - Art And Life
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Beenie Man - Youth Quake
drwxr-xr-x 2 sammy users 4.0K Nov 9 2003 Behind The Eye - EyeQ Compilation Vol.1
drwxr-xr-x 2 sammy users 4.0K Apr 7 2004 Big Beach Boutique II
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Bjoerk - Debut
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Bjoerk - Homogenic
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Bjoerk - Post
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Bjoerk - Selmasongs
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Bjoerk - Telegram
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Bjoerk - Vespertine
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Black Sabbath - Black Sabbath (remaster)
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Black Sabbath - Paranoid
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Blank & Jones - In The Mix
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Bloodhound Gang - Hooray for Boobies
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Bloodhoundgang - One Fierce Beer Coaster
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Blumentopf - Blumentopf
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Blumentopf - Eins A
drwxr-xr-x 2 sammy users 4.0K May 5 2004 Blumentopf - Gern Geschehen
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Blumentopf - Grosses Kino
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Bob Marley
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Bob Marley - Burnin'
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Bob Marley - Natural Mystic
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Body Count - Born Dead
drwxr-xr-x 2 sammy users 4.0K Oct 28 2003 Bomfunk MCs - In Stereo
drwxr-xr-x 4 sammy users 4.0K Oct 28 2003 Bossa Tres Jazz - When Japan Meets Europe
drwxr-xr-x 2 sammy users 4.0K May 6 2004 Buena Vista Social Club
drwxr-xr-x 2 sammy games 4.0K Nov 2 06:43 Bush - Deconstructed
...
the problems are:
- sometims the script isn't able to put the whole string into $albumToPlay. cut -f 2 seems to produce this error
- I don't want to create a temp file.
- it would be nicer if i could go through the listing line per line
- is there a tool something like: print_line ??
any ides on this??
greats