LinuxQuestions.org
Review your favorite Linux distribution.
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, 12:24 PM   #16
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15

Ok will try that .. Love this forum so quick and guys so friendly
 
Old 02-16-2010, 01:06 PM   #17
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
Ok onto next line..
I need help with the copy file function. I got the basic commands but how can you check for duplicates??
Have a look at the cksum command.

BTW, it is safest to use double quotes around variables that may have whitespace in them. That way you ensure their value is not parsed into multiple whitespace-separated words by the shell.
 
Old 02-16-2010, 03:25 PM   #18
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
OK still chuggin along here bit by bit but it gives me error near the end any ideas??
Code:
#!/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
this is where it chokes. any ideas??

'/12345_2_woot.txt: line 87: syntax error near unexpected token `in
'/12345_2_woot.txt: line 87: ` case "$ANS" in
 
Old 02-16-2010, 04:23 PM   #19
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
^ not quite sure but are you allowed to have a blank line after the case ?

rite after you read ANS can you do something like
Code:
debug: ANS = "$ANS"
maybe that will help us find the culprit.
____________________
http://tldp.org/LDP/abs/html/testbranch.html

maybe this will work
Code:
...
case "$ANS" in

    "c" | "C" ) create_playlist ;;

    "e" | "E" ) edit_playlist ;;

    "d" | "D" ) delete_playlist ;;

...
  esac

Last edited by schneidz; 02-16-2010 at 04:31 PM.
 
Old 02-16-2010, 10:18 PM   #20
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

this is where it chokes. any ideas??

'/12345_2_woot.txt: line 87: syntax error near unexpected token `in
'/12345_2_woot.txt: line 87: ` case "$ANS" in
Unbalanced quotes in (corrected)
Code:
cat "$AUDIOPATH"/tempdir.lst | while read line; do #Read each line of the file and store the line to $line variable
Missing fi and done in function copy_mp3.

Last edited by catkin; 02-16-2010 at 10:18 PM. Reason: Typo
 
Old 02-17-2010, 07:43 AM   #21
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
still chokin????

Code:
#!/bin/bash

PLAYLIST=/home/Fedora11

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
     done

     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
debug: ANS = "$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
/123456789_fedora11: line 63: syntax error near unexpected token `else'
./123456789_fedora11: line 63: ` else'

Last edited by m2dmhot; 02-17-2010 at 07:56 AM.
 
Old 02-17-2010, 08:15 AM   #22
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
Missing [[ ]] and ";" in
Code:
if [[ $line == $DONKEY ]]; then
and its closing "fi" is still missing.
 
Old 02-17-2010, 08:43 AM   #23
penguiniator
Member
 
Registered: Feb 2004
Location: Olympia, WA
Distribution: SolydK
Posts: 442
Blog Entries: 3

Rep: Reputation: 60
Go back to the previous "then" on line 61. You forgot the ; between the if clause and the then keyword. You also forgot the test command: [[ and ]]. Line 61 should read:
Code:
if [[ $line == $DONKEY ]]; then
The space after [[ and before ]] is required.

You can also reform your while read loop to:
Code:
while read line; do
   ...
done < "$AUDIOPATH"/tempdir.lst
This will eliminate piping the output of cat (which is almost never necessary) to read. Incidentally, you can also eliminate the echo before the read statement on line 56 by using read's -p argument.

Finally, you have an unterminated while loop beginning on line 87. Unless, of course, this is only a code fragment, which is suggested by the ... on line 106.
 
Old 02-17-2010, 08:48 AM   #24
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by catkin View Post
Missing [[ ]] and ";" in
Code:
if [[ $line == $DONKEY ]]; then
and its closing "fi" is still missing.

im not catching what your saying??

Code:
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
                                     ...
                                    done < "$AUDIOPATH"/temp.lst
        if [[ $line == $DONKEY ]]; then
            echo "File Already Exist, Copy Aborted!"
        else
            cp $DONKEY "$PLAYLIST"/MP3_1
       fi
     done

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

}

Last edited by m2dmhot; 02-17-2010 at 08:56 AM.
 
Old 02-17-2010, 08:58 AM   #25
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by penguiniator View Post
Go back to the previous "then" on line 61. You forgot the ; between the if clause and the then keyword. You also forgot the test command: [[ and ]]. Line 61 should read:
Code:
if [[ $line == $DONKEY ]]; then
The space after [[ and before ]] is required.

You can also reform your while read loop to:
Code:
while read line; do
   ...
done < "$AUDIOPATH"/tempdir.lst
This will eliminate piping the output of cat (which is almost never necessary) to read. Incidentally, you can also eliminate the echo before the read statement on line 56 by using read's -p argument.

Finally, you have an unterminated while loop beginning on line 87. Unless, of course, this is only a code fragment, which is suggested by the ... on line 106.
Im a newb dont forget lol kinda have to hold my hand.. still learning
 
Old 02-17-2010, 08:58 AM   #26
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
^ at the end of an if,then,else statement you need to fi so that bash knows where the conditional statement ends.
_____
i see from your last edit 5 mins. ago, you did it rite.

Last edited by schneidz; 02-17-2010 at 09:01 AM.
 
Old 02-17-2010, 09:11 AM   #27
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by schneidz View Post
^ not quite sure but are you allowed to have a blank line after the case ?

rite after you read ANS can you do something like
Code:
debug: ANS = "$ANS"
maybe that will help us find the culprit.
____________________
http://tldp.org/LDP/abs/html/testbranch.html

maybe this will work
Code:
...
case "$ANS" in

    "c" | "C" ) create_playlist ;;

    "e" | "E" ) edit_playlist ;;

    "d" | "D" ) delete_playlist ;;

...
  esac
Dying on line 119 does this look right??

Code:
...
 read ANS
debug: ANS = "$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
/123456789_fedora11: line 119: syntax error near unexpected token `newline'
./123456789_fedora11: line 119: `...'

Last edited by m2dmhot; 02-17-2010 at 09:13 AM.
 
Old 02-17-2010, 09:12 AM   #28
casperz
LQ Newbie
 
Registered: Feb 2010
Location: Ontario
Distribution: Mandriva, Fedora 11
Posts: 3

Rep: Reputation: 0
This script looks pretty cool.
Can you post it when you get up and running?
I am trying to do something similar to this.
 
Old 02-17-2010, 09:33 AM   #29
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
can you print it with line numbers
Code:
grep -n . script.ksh
maybe it is choking on this
Quote:
"1" | ) copy_mp3 ;;
"2" | ) delete_mp3 ;;
the | are probably not needed.
in this instance | means or.

Last edited by schneidz; 02-17-2010 at 09:37 AM.
 
Old 02-17-2010, 09:50 AM   #30
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by schneidz View Post
can you print it with line numbers
Code:
grep -n . script.ksh
maybe it is choking on thisthe | are probably not needed.
in this instance | means or.
Code:
1:#!/bin/bash
3:PLAYLIST=/home/Fedora11
5:AUDIOPATH=$PLAYLIST/MP3
7:## Functions for each task
9:create_playlist() { 
11:   cd "$AUDIOPATH"
12:   echo -e "Enter Name Of Playlist --> \c"
13:   read PNAME
14:   touch $PNAME.m3u
16:   echo -e
17:   ls -v *.mp3
18:   echo -e
19:}
23:edit_playlist() { 
24:   : put appropriate commands here
25:}
28:delete_playlist() { 
29:  : put appropriate commands here
30:}
33:generate_playlist() { 
34:  : put appropriate commands here
35:}
39:play_mp3() { 
41:    cd "$AUDIOPATH"
42:    ls -v *.mp3
43:    echo -e
44:    echo -e "Please Select Your Song --> \c"
45:    IFS= read DOG
46:    mplayer "$AUDIOPATH"/$DOG 
48:}
51:copy_mp3() { 
53:    cd "$AUDIOPATH"
54:    ls -v *.mp3 >> "$AUDIOPATH"/tempdir.lst # Create Temp file with Directory listing
56:    echo -e "Please Select Your Song To Copy --> \c"
57:    read DONKEY
60:    cat "$AUDIOPATH"/tempdir.lst | while read line; do #Read each line of the file and store the line to $line variable
61:                                     ...
62:                                    done < "$AUDIOPATH"/temp.lst
63:        if [[ $line == $DONKEY ]]; then
64:            echo "File Already Exist, Copy Aborted!"
65:        else
66:            cp $DONKEY "$PLAYLIST"/MP3_1
67:       fi
68:     
69:     rm "$AUDIOPATH"/tempdir.lst # Delete the temporary file containing the directory listing
71:}
74:delete_mp3() { 
76:    cd "$AUDIOPATH"
77:    ls -v *.mp3
78:    echo -e
80:    echo -e "Please Select Which Song To Delete --> \c"
81:    read SONG
82:    rm $SONG
83:    cd "$AUDIOPATH" || exit 1 
85:}
87:## Print menu and execute user's selection
89:while  :
90:do
91:  printf %s '
94:Mp3 Playlist Program:
95:================================
96:C)reate Mp3 Playlist
97:E)dit Mp3 Playlists
98:D)isplay Mp3 Playlists
99:G)enerate Mp3 Database
100:P)lay Mp3
101:1)Copy Mp3
102:2)Remove Mp3
103:Q)uit
104:Enter your selection ==> '
106:read ANS
107:#debug: ANS = $ANS
109:case $ANS in

110:    c|C ) create_playlist 
111:          ;;

112:    e|E ) edit_playlist 
113:          ;;

114:    d|D ) delete_playlist 
115:          ;;

116:    g|G ) generate_playlist 
117:          ;;

118:    p|P ) play_mp3 
119:          ;;

120:    1)    copy_mp3 
121:          ;;

122:    2)    delete_mp3 
123:          ;;

124:    q|Q ) exit 
125:          ;;

126:esac

127:
i got rid of the quotations on the letters thinking that might fix it but nope

Last edited by m2dmhot; 02-17-2010 at 09:52 AM.
 
  


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 04:43 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