LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 12-12-2004, 11:41 AM   #1
Sammy2ooo
Member
 
Registered: Jan 2003
Location: nearby switzerland
Distribution: Suse 8.0 / Suse 9.0 / Slackware 9.1 / Debian Sarge testing / Gentoo 1.4.10
Posts: 165

Rep: Reputation: 30
bash scripting problem


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

Last edited by Sammy2ooo; 12-12-2004 at 12:21 PM.
 
Old 12-13-2004, 04:43 AM   #2
Sammy2ooo
Member
 
Registered: Jan 2003
Location: nearby switzerland
Distribution: Suse 8.0 / Suse 9.0 / Slackware 9.1 / Debian Sarge testing / Gentoo 1.4.10
Posts: 165

Original Poster
Rep: Reputation: 30
hm if someone could tell me if there's a tool out there (or included in bash) for printing only one special line, i would be happy

e.g.

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
...
Code:
ls -l /home/sammy/MP3z | printLine 3 
-> drwxr-xr-x   2 sammy users 4.0K Oct 28  2003 Barry White - All Time Greatest Hits
 
Old 12-13-2004, 10:36 AM   #3
LasseW
Member
 
Registered: Oct 2004
Distribution: Fedora 7, OpenSuse 10.2
Posts: 108

Rep: Reputation: 15
cat /home/sammy/MP3z | sed -n '3p'
 
Old 12-13-2004, 01:31 PM   #4
Sammy2ooo
Member
 
Registered: Jan 2003
Location: nearby switzerland
Distribution: Suse 8.0 / Suse 9.0 / Slackware 9.1 / Debian Sarge testing / Gentoo 1.4.10
Posts: 165

Original Poster
Rep: Reputation: 30
ah great, thx for your help
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash scripting problem (bug?) zz9pluralzalpha Linux - Software 2 04-12-2005 02:51 PM
bash scripting problem sutley Linux - Software 1 12-17-2004 12:33 PM
BASH Scripting Design Problem... amaze Linux - General 1 08-19-2003 09:30 AM
BASH scripting problem deadlock Programming 5 08-15-2003 05:33 AM
bash scripting problem raven Programming 7 03-10-2003 06:48 PM


All times are GMT -5. The time now is 12:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration