Help with bash script.

Hello all I am newbie to Linux. After hours of reading and trying to compile something myself I am just uterly frusterated.
I am looking for some help maybee someone who has bit of free time to maybee show me an example of how to create a bash script to suit my needs.

Requirements
Ability to create, edit display and remove playlist files.
Ability to create edit and automatically generate and update an mp3 database file.
Ability to copy and remove mp3 files and verify there are no duplicate files in a directory.
Ability to play individual songs or playlists sort of in a menu type

Not asking for you to do the work jsut maybee show me an example for each.. Thanks in advance

Use redirection to send output to an M3U file.

What is the format of the database file? What database program are you using?

Read the man pages for cp and rm

What software are you using to play the files?

#!/bin/bash

PLAYLIST='/home/Fedora11'

function mk_playlist
{
AUDIOPATH='/home/Fedora11/MP3'

touch /home/Fedora11/playlist
touch /home/Fedora11/temporaryplaylist

find $AUDIOPATH -print -type f > /home/Fedora11/temporaryplaylist
grep -i 'mp3$' /home/Fedora11/temporaryplaylist > /home/Fedora11/playlist


rm /home/Fedora11/temporaryplaylist

echo Total files: `wc -l /home/Fedora11/playlist`
}

# Echo some help
if [ "$1" == "-h" -o "$1" == "--help" ]; then
echo "Usage: doze [OPTION]"
echo
echo "<minutes> Doze for <minutes> and start playing"
echo "-c | --create Create playlist w/o playing it"
echo "-h | --help Show this help"
echo
echo "W/o option playing starts immediately"
echo
exit 0
fi

# Just create playlist w/o playing it
if [ "$1" == "-c" -o "$1" == "--create" ]; then
mk_playlist
exit 0
fi

# Start playing immediately
if [ "$#" -ne 1 ]; then
if [ ! -f "$PLAYLIST" ]; then
mk_playlist
mplayer -shuffle -playlist $PLAYLIST
else
mplayer -shuffle -playlist $PLAYLIST
fi
else
# Or after a while
if [ ! -f "$PLAYLIST" ]; then
mk_playlist
TIME_IN_MINS=$(($1 * 60))
sleep $TIME_IN_MINS
mplayer -shuffle -playlist $PLAYLIST
else
TIME_IN_MINS=$(($1 * 60))
sleep $TIME_IN_MINS
mplayer -shuffle -playlist $PLAYLIST
fi
fi

Basically i have taken bit of pieces i have found from my book and reading..
Ultimately i want to create a menu that will allow me to select create playlist edit playlist adding and deleting mp3s. play playlist . Also check for duplicates .This tidbit on this script was added feature to play the playlist or generate one and add a snooze time

That is not the standard syntax for defining a function.

mk_playlist()
{

There is no need to quote a variable assignment unless there is literal whitespace or other special characters.

You have created a variable for the directory; why are you not using it?

AUDIOPATH=$PLAYLIST/MP3

You should never again have the literal '/home/Fedora11' in your script.

If you really need to create these files ahead of time, there is no need to use an external command (touch):

> "$PLAYLIST/playlist"
> "$PLAYLIST/temporaryplaylist"

You don't need grep or a temporary file:

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

Now, what's your question?

What is not working in your script?

Is the above not the way you request it???

It's fine, now, but you should indent your code.

Ok im going line by line here with you..
i understand what you said about standard syntax for defining a function.
now.. My mp3 are stored in /home/Fedora11/MP3
You state there is no need to quote a variable assignment unless there is a literal white space or other special characters.
if you put

AUDIOPATH=$PLAYLIST/MP3

how does it know where the mp3 are???

then you state that if you really need to create these files ahead fo time there is no need to use external command touch. again your removing the directory listing. How does it know where the directories are??

Ill wait to you reply with this then ill jump down to the next

You tell it. Presumably, "$AUDIOPATH" contains the directory with the mp3s. If not, why did you assign it?

You tell it. That's what the variable is for.

Why are you putting playlist infront of the mp3???

I didn't; you did.

You had:

AUDIOPATH='/home/Fedora11/MP3'

That is the same thing as:

AUDIOPATH=$PLAYLIST/MP3

I wish you'd post the parts of the script that are giving you problems and tell us exactly what the problem is; then maybe we could be of more help.

My problem is im just trying to make my own script.. Im a complete newb.
This course im taking is rammed down our throats i cant learn fedora in 3 weeks. Its just not happening. Im gettin to the point where im just very frusterated. IM trying to go line by line here and understand how to piece this together.
my mp3 are stored in
/home/Fedora11/MP3
playlist will reside in /home/Fedora11
i will mess around more here. and paste back then try again..

---------- Post updated at 04:32 PM ---------- Previous update was at 03:49 PM ----------

OK im trying dif approach now.. I have my menu made up i will take it one step at a time.. Sorry for being a complete newb. If you dont mind me going baby steps that would be great.

#!/bin/bash
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
          ;;

So now i assume i have to make a variable that tells it that CREATEPLAYLIST
does this ??

mk_playlist()
{

---------- Post updated 02-16-10 at 08:19 AM ---------- Previous update was 02-15-10 at 04:32 PM ----------

anyone??

---------- Post updated at 08:47 AM ---------- Previous update was at 08:19 AM ----------

ok I now understand what you mean about the Playlist assigining it where it is in reference..
what im stuck on is assigining the command fromt he variable in the menu

#!/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

What command from what variable?

I suggest that you create a separate function for each of the various actions the user may select.

im a newb. i dont have the sligthest clue what your talkin about.. Im at the point where i just gonna give up. You just dont learn this stuff overnight..

## 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

Now were cookin with gasoline.. I will take time to see what you did and enter in the empty variable.. this is what I needed a miiiiiiiiiilllllllllllllllllion thank yous

---------- Post updated at 01:16 PM ---------- Previous update was at 10:04 AM ----------

Ok making some progress here line by line.. IM stuck at the copying options
i got the basic copy cmd to work but need help to detect duplicate??
heres what i got so far

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/ 
}

Use the test command:

if [ -f "$destfile" ] then ...

Why are you hard-coding the directory name when you have it in a variable?

And always check that you changed directory successfully:

cd "$AUDIOPATH" || exit 1

That will fail if $DONKEY contains whitespace. Always quote variable references:

cp "$DONKEY" "$PLAYLIST/MP3_1/"

Im not using the old one. I used the one you created. How will it knwo the path if im not assigning it.. I dont know proper procedure for scripting. I just add bits and pieces trying to make it work..

## Functions for each task
create_playlist() { 
   cd /home/Fedora11
   echo -e "Enter Name Of Playlist --> \c"
   read PNAME
   touch $PNAME.m3u
   
   echo -e
   ls -v *.mp3
   echo -e
}

edit_playlist() { 
  : put appropriate commands here
}

delete_playlist() { 
  : put appropriate commands here
}

generate_playlist() { 
  : put appropriate commands here
}

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" 
}

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/" 
}

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

    echo -e "Please Select Which Song To Delete --> \c"
    read SONG
    rm $SONG 
}

## 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

now im still unsure where your putting the

if [ -f "$destfile" ] then ...

or how your using like.. I appoligize but im not as advanced as you think.

I didn't write a complete script.

You should assign variables at the beginning of your script. That way, if you need to do the same thing in another directory you can just change one instance.

Geez i feel so stupid.. ok i added that path. But not sure if i have to add cd in front of all the required paths??
here is what i got with newest but giving me error on line 89

#!/bin/bash

PLAYLIST='/home/woot'

AUDIOPATH=$PLAYLIST/MP3

## Functions for each task

create_playlist() { 

   cd "$AUDIOPATH"

   echo -e "Enter Name Of Playlist --> \c"

   read PNAME

   touch $PNAME.m3u

   

   echo -e

   ls -v *.mp3

   echo -e

}



edit_playlist() { 

  : put appropriate commands here

}



delete_playlist() { 

  : put appropriate commands here

}



generate_playlist() { 

  : put appropriate commands here

}



play_mp3() { 

    cd "$AUDIOPATH"

    ls -v *.mp3

    echo -e



    echo -e "Please Select Your Song --> \c"

    IFS= read DOG

    mplayer "$AUDIOPATH"/$DOG" 

}



copy_mp3() { 

    cd "$AUDIOPATH

    ls -v *.mp3 >> "$AUDIOPATH"/tempdir.lst # Create Temp file with Directory listing



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

    read DONKEY



    cat '$AUDIOPATH"/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" "$PLAYLIST_MP3_1/"

       

    rm "$AUDIOPATH"/tempdir.lst # Delete the temporary file containing the directory listing

}



delete_mp3() { 

    cd "$AUDIOPATH"

    ls -v *.mp3

    echo -e



    echo -e "Please Select Which Song To Delete --> \c"

    read SONG

    rm $SONG
    cd "$AUDIOPATH" || exit 1 

}



## 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

'/12345_2_woot.txt: line 89: syntax error near unexpected token `in
'/12345_2_woot.txt: line 89: ` case "$ANS" in

If you want to cd into the directory, you need cd; if you don't, you don't.

The quotes are not necessary.

PLAYLIST=/home/woot

You have unmatched quotes.