# Help with bash script.

**URL:** <https://community.unix.com/t/help-with-bash-script/259720>\
**Category:** Shell Programming and Scripting\
**Created:** [February 15, 2010, 1:34pm UTC](https://community.unix.com/t/help-with-bash-script/259720 "2010-02-15T13:34:19Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![m2dmhot](https://community.unix.com/letter_avatar/m2dmhot/32/6_449c533f586939b6e5f246632a46421f.png) [@m2dmhot](https://community.unix.com/u/m2dmhot)\
**Post date:** [February 15, 2010, 1:34pm UTC](https://community.unix.com/t/help-with-bash-script/259720/1 "2010-02-15T13:34:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [February 15, 2010, 1:43pm UTC](https://community.unix.com/t/help-with-bash-script/259720/2 "2010-02-15T13:43:10Z")

</div>

> [@m2dmhot](#):
>
> 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.

Use redirection to send output to an M3U file.

> [@](#):
>
> Ability to create edit and automatically generate and update an mp3 database file.

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

> [@](#):
>
> Ability to copy and remove mp3 files and verify there are no duplicate files in a directory.

Read the man pages for cp and rm

> [@](#):
>
> Ability to play individual songs or playlists sort of in a menu type

What software are you using to play the files?

> [@](#):
>
> Not asking for you to do the work jsut maybee show me an example for each.. Thanks in advance

---

<div class="post-metadata">

**Author:** ![m2dmhot](https://community.unix.com/letter_avatar/m2dmhot/32/6_449c533f586939b6e5f246632a46421f.png) [@m2dmhot](https://community.unix.com/u/m2dmhot)\
**Post date:** [February 15, 2010, 2:16pm UTC](https://community.unix.com/t/help-with-bash-script/259720/3 "2010-02-15T14:16:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [February 15, 2010, 2:20pm UTC](https://community.unix.com/t/help-with-bash-script/259720/4 "2010-02-15T14:20:54Z")

</div>

> [@](#):
>
> ```plaintext
> #!/bin/bash
> 
> PLAYLIST='/home/Fedora11'
> 
> function mk_playlist
> {
> 
> ```

That is not the standard syntax for defining a function.

```plaintext
mk_playlist()
{

```

> [@](#):
>
> ```plaintext
> AUDIOPATH='/home/Fedora11/MP3'
> 
> ```

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?

```plaintext
AUDIOPATH=$PLAYLIST/MP3

```

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

> [@](#):
>
> ```plaintext
> touch /home/Fedora11/playlist
> touch /home/Fedora11/temporaryplaylist
> 
> ```

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

```plaintext
> "$PLAYLIST/playlist"
> "$PLAYLIST/temporaryplaylist"

```

> [@](#):
>
> ```plaintext
> find $AUDIOPATH -print -type f > /home/Fedora11/temporaryplaylist
> grep -i 'mp3$' /home/Fedora11/temporaryplaylist > /home/Fedora11/playlist
> 
> ```

You don't need grep or a temporary file:

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

```

> [@](#):
>
> ```plaintext
> 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
> 
> ```

Now, what's your question?

What is not working in your script?

---

<div class="post-metadata">

**Author:** ![m2dmhot](https://community.unix.com/letter_avatar/m2dmhot/32/6_449c533f586939b6e5f246632a46421f.png) [@m2dmhot](https://community.unix.com/u/m2dmhot)\
**Post date:** [February 15, 2010, 2:27pm UTC](https://community.unix.com/t/help-with-bash-script/259720/5 "2010-02-15T14:27:03Z")

</div>

> [@cfajohnson](#):
>
> Please edit your post and remove the duplication and put the code, and only the code, in [code] tags.

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

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [February 15, 2010, 2:42pm UTC](https://community.unix.com/t/help-with-bash-script/259720/6 "2010-02-15T14:42:23Z")

</div>

> [@m2dmhot](#):
>
> Is the above not the way you request it???

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

---

<div class="post-metadata">

**Author:** ![m2dmhot](https://community.unix.com/letter_avatar/m2dmhot/32/6_449c533f586939b6e5f246632a46421f.png) [@m2dmhot](https://community.unix.com/u/m2dmhot)\
**Post date:** [February 15, 2010, 3:11pm UTC](https://community.unix.com/t/help-with-bash-script/259720/7 "2010-02-15T15:11:00Z")

</div>

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

```nohighlight
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

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [February 15, 2010, 3:15pm UTC](https://community.unix.com/t/help-with-bash-script/259720/8 "2010-02-15T15:15:34Z")

</div>

> [@m2dmhot](#):
>
> 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
> 
> ```plaintext
> AUDIOPATH=$PLAYLIST/MP3
> 
> ```
> 
> how does it know where the mp3 are???

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

> [@](#):
>
> 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??

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

---

<div class="post-metadata">

**Author:** ![m2dmhot](https://community.unix.com/letter_avatar/m2dmhot/32/6_449c533f586939b6e5f246632a46421f.png) [@m2dmhot](https://community.unix.com/u/m2dmhot)\
**Post date:** [February 15, 2010, 3:33pm UTC](https://community.unix.com/t/help-with-bash-script/259720/9 "2010-02-15T15:33:46Z")

</div>

> [@cfajohnson](#):
>
> 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???

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [February 15, 2010, 3:44pm UTC](https://community.unix.com/t/help-with-bash-script/259720/10 "2010-02-15T15:44:23Z")

</div>

> [@m2dmhot](#):
>
> Why are you putting playlist infront of the mp3???

I didn't; you did.

You had:

```plaintext
AUDIOPATH='/home/Fedora11/MP3'

```

That is the same thing as:

```plaintext
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.

---

<div class="post-metadata">

**Author:** ![m2dmhot](https://community.unix.com/letter_avatar/m2dmhot/32/6_449c533f586939b6e5f246632a46421f.png) [@m2dmhot](https://community.unix.com/u/m2dmhot)\
**Post date:** [February 16, 2010, 8:47am UTC](https://community.unix.com/t/help-with-bash-script/259720/11 "2010-02-16T08:47:34Z")

</div>

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.

```plaintext
#!/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 ??

```plaintext
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 ----------

> [@cfajohnson](#):
>
> I didn't; you did.
> 
> You had:
> 
> ```plaintext
> AUDIOPATH='/home/Fedora11/MP3'
> 
> ```
> 
> That is the same thing as:
> 
> ```plaintext
> 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.

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

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

```

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [February 16, 2010, 9:37am UTC](https://community.unix.com/t/help-with-bash-script/259720/12 "2010-02-16T09:37:11Z")

</div>

> [@m2dmhot](#):
>
> what im stuck on is assigining the command fromt he variable in the menu

What command from what variable?

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

---

<div class="post-metadata">

**Author:** ![m2dmhot](https://community.unix.com/letter_avatar/m2dmhot/32/6_449c533f586939b6e5f246632a46421f.png) [@m2dmhot](https://community.unix.com/u/m2dmhot)\
**Post date:** [February 16, 2010, 9:39am UTC](https://community.unix.com/t/help-with-bash-script/259720/13 "2010-02-16T09:39:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [February 16, 2010, 9:48am UTC](https://community.unix.com/t/help-with-bash-script/259720/14 "2010-02-16T09:48:58Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![m2dmhot](https://community.unix.com/letter_avatar/m2dmhot/32/6_449c533f586939b6e5f246632a46421f.png) [@m2dmhot](https://community.unix.com/u/m2dmhot)\
**Post date:** [February 16, 2010, 1:16pm UTC](https://community.unix.com/t/help-with-bash-script/259720/15 "2010-02-16T13:16:46Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [February 16, 2010, 1:25pm UTC](https://community.unix.com/t/help-with-bash-script/259720/16 "2010-02-16T13:25:58Z")

</div>

> [@m2dmhot](#):
>
> 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??

Use the test command:

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

```

> [@](#):
>
> heres what i got so far
> 
> ```plaintext
> copy_mp3() { 
> cd /home/Fedora11/MP3/
> 
> ```

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

And always check that you changed directory successfully:

```plaintext
cd "$AUDIOPATH" || exit 1

```

> [@](#):
>
> ```plaintext
> ls -v *.mp3
>    
> echo -e "Please Select Your Song To Copy --> \c"
> read DONKEY
> cp $DONKEY /home/Fedora11/MP3_1/ 
> }
> 
> ```

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

```plaintext
cp "$DONKEY" "$PLAYLIST/MP3_1/"

```

---

<div class="post-metadata">

**Author:** ![m2dmhot](https://community.unix.com/letter_avatar/m2dmhot/32/6_449c533f586939b6e5f246632a46421f.png) [@m2dmhot](https://community.unix.com/u/m2dmhot)\
**Post date:** [February 16, 2010, 1:44pm UTC](https://community.unix.com/t/help-with-bash-script/259720/17 "2010-02-16T13:44:00Z")

</div>

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

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

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

```

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

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [February 16, 2010, 1:47pm UTC](https://community.unix.com/t/help-with-bash-script/259720/18 "2010-02-16T13:47:24Z")

</div>

> [@m2dmhot](#):
>
> Im not using the old one. I used the one you created. How will it knwo the path if im not assigning it..

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.

---

<div class="post-metadata">

**Author:** ![m2dmhot](https://community.unix.com/letter_avatar/m2dmhot/32/6_449c533f586939b6e5f246632a46421f.png) [@m2dmhot](https://community.unix.com/u/m2dmhot)\
**Post date:** [February 16, 2010, 2:28pm UTC](https://community.unix.com/t/help-with-bash-script/259720/19 "2010-02-16T14:28:45Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [February 16, 2010, 2:45pm UTC](https://community.unix.com/t/help-with-bash-script/259720/20 "2010-02-16T14:45:38Z")

</div>

> [@m2dmhot](#):
>
> 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??

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

> [@](#):
>
> here is what i got with newest but giving me error on line 89
> 
> ```plaintext
> #!/bin/bash
> 
> PLAYLIST='/home/woot'
> 
> ```

The quotes are not necessary.

```plaintext
PLAYLIST=/home/woot

```

> [@](#):
>
> ```plaintext
> mplayer "$AUDIOPATH"/$DOG" 
> 
> ```

You have unmatched quotes.

[Next page](https://community.unix.com/t/help-with-bash-script/259720.md?page=2)
