LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-16-2010, 07:56 AM   #1
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Rep: Reputation: 15
Help with bash script


hello im trying to make a menu type mp3 playist program from a bash script. im stuck on assigining the menu the variable. Please if anyone can throw some feedback whats wrong here thanks in advance.
im using mplayer and playlist needs to reside in
/home/Fedora11 and mp3 will reside in /home/Fedora11/MP3
Code:
#!/bin/bash


    PLAYLIST='/home/Fedora11'

    mk_playlist()
    {

AUDIOPATH=$PLAYLIST/MP3

find "$AUDIOPATH" -type f -name '*.[Mm][Pp]3' > /home/Fedora11/playlist



while  :                             #This always returns true (see /bin/true and :)
do
echo -e 'Mp3 Playlist Program:
================================
C)reate Mp3 Playlist
E)dit Mp3 Playlists
D)isplay Mp3 Playlists
G)enerate Mp3 Database
P)lay Mp3
1)Copy Mp3
2)Remove Mp3
Q)uit
Enter your selection ==> \c'

read ANS


case "$ANS" in
c  | C  ) echo e- "Create A Play List? --> \c"
          read CREATEPLAYLIST
          
          echo -e "$CREATEPLAYLIST" >> /home/Fedora11
          ;;
esac
done
 
Old 02-16-2010, 08:18 AM   #2
irmin
Member
 
Registered: Jan 2010
Location: the universe
Distribution: Slackware (modified), Slackware64 (modified), openSuSE (modified)
Posts: 342

Rep: Reputation: 62
First of all you forgot to close the function definition of mk_playlist().

Quote:
echo -e "$CREATEPLAYLIST" >> /home/Fedora11
What is this line supposed to do?
 
Old 02-16-2010, 08:30 AM   #3
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by irmin View Post
First of all you forgot to close the function definition of mk_playlist().



What is this line supposed to do?
Im not sure?? im a newb.. Im very frusterated upon hours of reasearching and reading.. I am just trying to do this the best way i been taking bits and pieces from what people are telling me to do..
I need to create a playlist menu. list i have put in the script.
be able to read the mp3 in /home/Fedora11/mp3 and make a playlist
in /home/Fedora11 but i have the sligtest clue even where to start??
 
Old 02-16-2010, 08:44 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by m2dmhot View Post
Im not sure?? im a newb.. Im very frusterated upon hours of reasearching and reading.. I am just trying to do this the best way i been taking bits and pieces from what people are telling me to do.
Welcome to LQ

Relax. Smile. Count to 100 while breathing deeply

Surely we can help you. The first step is to be very clear about what you want to do. We're pretty smart but not mind readers so you are going to have to tell us. You're new to all this and probably don't know exactly what you want to do but that's OK -- we can work together on that. Tell us the best you can, tell us what you are uncertain about and we can go forward from there.
 
Old 02-16-2010, 09:11 AM   #5
penguiniator
Member
 
Registered: Feb 2004
Location: Olympia, WA
Distribution: SolydK
Posts: 442
Blog Entries: 3

Rep: Reputation: 60
Try typing 'help select' at a bash prompt.
 
Old 02-16-2010, 09:14 AM   #6
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
ok i am using mplayer.
i would like the ability to create display and remove playlists.
Playlist will reside in /home/Fedora11 and the mp3s are in
/home/Fedora11/MP3
I also need a database file that shows the path directory.
ability to play mp3 and add mp3 to the playlist and check for duplicates.
I want it in sort of a menu type options something like this
Code:
## Functions for each task
create_playlist() { 
  : put appropriate commands here
}

edit_playlist() { 
  : put appropriate commands here
}

delete_playlist() { 
  : put appropriate commands here
}

generate_playlist() { 
  : put appropriate commands here
}

play_mp3() { 
  : put appropriate commands here
}

copy_mp3() { 
  : put appropriate commands here
}

delete_mp3() { 
  : put appropriate commands here
}

## Print menu and execute user's selection
while  :
do
  printf %s '

Mp3 Playlist Program:
================================
C)reate Mp3 Playlist
E)dit Mp3 Playlists
D)isplay Mp3 Playlists
G)enerate Mp3 Database
P)lay Mp3
1)Copy Mp3
2)Remove Mp3
Q)uit
Enter your selection ==> '

  read ANS

  case "$ANS" in
    c|C ) create_playlist ;;
    e|E ) edit_playlist ;;
    d|D ) delete_playlist ;;
    g|G ) generate_playlist ;;
    p|P ) play_mp3 ;;
    1)    copy_mp3 ;;
    2)    delete_mp3 ;;
    q|Q ) exit ;;
  esac
done

I have been bouncing back from forums and reading but really unsure what the next step to acutally make the options work. If i could get one to work i could try to geth the others to work..
Also a friend said that this has to be linear so the first part of the script has to come after the menu??
 
Old 02-16-2010, 09:59 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Thanks for more info

I don't use any music players so can't help with that side of things but I can help with the scripting side.

Shell functions need to be defined before they are called so your layout is the right one.

In your original code you had echo e-

You can check that the menu is calling the functions by something like
Code:
edit_playlist() {
  echo "DEBUG: function ${FUNCNAME[0]} started" 
  : put appropriate commands here
}
 
Old 02-16-2010, 10:05 AM   #8
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Ok i got some progress here. Tackled the play mp3 so far
modded it a bit with litle help i added this cmd but it doesnt like when i enter in songs with spaces how can i fix this??
Code:
play_mp3() { 
    cd /home/Fedora11/MP3/
    ls -v *.mp3
    echo -e

    echo -e "Please Select Your Song --> \c"
    read SONG
    mplayer $SONG 
}
 
Old 02-16-2010, 10:22 AM   #9
irmin
Member
 
Registered: Jan 2010
Location: the universe
Distribution: Slackware (modified), Slackware64 (modified), openSuSE (modified)
Posts: 342

Rep: Reputation: 62
read splits the input into words. The delimiters are in IFS.

Try the following:
Code:
IFS= read SONG
mplayer $SONG
 
Old 02-16-2010, 10:35 AM   #10
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
this mite help:
http://www.linuxquestions.org/questi...center-719104/

Last edited by schneidz; 02-16-2010 at 10:40 AM.
 
Old 02-16-2010, 10:55 AM   #11
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by irmin View Post
read splits the input into words. The delimiters are in IFS.

Try the following:
Code:
IFS= read SONG
mplayer $SONG
Just tried that it keeps looking for individual names..

Code:
play_mp3() { 
    cd /home/Fedora11/MP3/
    ls -v *.mp3
    echo -e

    echo -e "Please Select Your Song --> \c"
    IFS= read DOG
    mplayer $DOG 
}
 
Old 02-16-2010, 11:09 AM   #12
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Got it now...
Code:
play_mp3() { 
    cd /home/Fedora11/MP3/
    ls -v *.mp3
    echo -e

    echo -e "Please Select Your Song --> \c"
    IFS= read DOG
    mplayer "/home/Fedora11/MP3/$DOG"
 
Old 02-16-2010, 12:04 PM   #13
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Ok onto next line..
I need help with the copy file function. I got the basic commands but how can you check for duplicates??

Code:
copy_mp3() { 
    cd /home/Fedora11/MP3/
    ls -v *.mp3
    
    echo -e "Please Select Your Song To Copy --> \c"
    read DONKEY
    cp $DONKEY /home/Fedora11/MP3_1/ 
}
 
Old 02-16-2010, 12:16 PM   #14
worm5252
Member
 
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX, OS X
Posts: 567

Rep: Reputation: 57
You could create a temp file with a directory listing. Then you can read the file line by line to see if the file exist. If it does, then do nothing, if it doesn't then copy the file.

Code:
copy_mp3() { 
    cd /home/Fedora11/MP3/
    ls -v *.mp3 >> /home/Fedora11/MP3/tempdir.lst # Create Temp file with Directory listing

    echo -e "Please Select Your Song To Copy --> \c"
    read DONKEY

    cat /home/Fedora11/MP3/tempdir.lst | while read line; do #Read each line of the file and store the line to $line variable
        if $line == $DONKEY then
            echo "File Already Exist, Copy Aborted!"
        else
            cp $DONKEY /home/Fedora11/MP3_1/
    done    

    rm /home/Fedora11/MP3/tempdir.lst # Delete the temporary file containing the directory listing
}

Last edited by worm5252; 02-16-2010 at 12:18 PM.
 
Old 02-16-2010, 12:19 PM   #15
worm5252
Member
 
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX, OS X
Posts: 567

Rep: Reputation: 57
This Post would probably do better in the Programming forum
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM
[SOLVED] bash : getopts problem in bash script. angel115 Programming 2 03-02-2009 10:53 AM
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 06:00 AM
Bash script to create bash script jag7720 Programming 10 09-10-2007 07:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:30 AM.

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
Open Source Consulting | Domain Registration