LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-17-2010, 10:02 AM   #31
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

Please don't change the posted scripts when you fix an error; it's very confusing. Better add an "EDIT: " line at the top of the post to let us know you have moved on from the posted script and post the new one in another post.

BTW, regards
Code:
read ANS
ANS = $ANS
Assignments must not have space either side of the = sign so you wanted ANS=$ANS except you don't because it doesn't do anything, IYSWIM.

Last edited by catkin; 02-17-2010 at 10:04 AM.
 
Old 02-17-2010, 10:11 AM   #32
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
^ that should be
Code:
echo debug: ANS = "$ANS"
i put that in so that we would know what the value of the ANS variable was in case it was not being assigned correctly.

i dont know, i dont use cases much. maybe a space between 1 and ) and 2 and ) like the ones above it ?

is it still complaining about line 119 ?

Last edited by schneidz; 02-17-2010 at 10:21 AM.
 
Old 02-17-2010, 10:33 AM   #33
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 schneidz View Post
i dont know, i dont use cases much. maybe a space between 1 and ) and 2 and ) like the ones above it ?
In case commands the space between pattern and ) is optional.
 
Old 02-17-2010, 10:36 AM   #34
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by schneidz View Post
^ that should be
Code:
echo debug: ANS = "$ANS"
i put that in so that we would know what the value of the ANS variable was in case it was not being assigned correctly.

i dont know, i dont use cases much. maybe a space between 1 and ) and 2 and ) like the ones above it ?

is it still complaining about line 119 ?
Ok i went back to original script with the latest help..
still chokin near bottom line 118
./123456789_fedora11: line 118: syntax error near unexpected token `newline'
./123456789_fedora11: line 118: `... '


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"
108:...
109: case "$ANS" in
110:    "c" | "C" ) create_playlist ;;
111:    "e" | "E" ) edit_playlist ;;
112:    "d" | "D" ) delete_playlist ;;
113:    "g" | "G" ) generate_playlist ;;
114:    "p" | "P" ) play_mp3 ;;
115:    "o" | "O" ) copy_mp3 ;;
116:    "l" | "L" ) delete_mp3 ;;
117:    "q "| "Q" ) exit ;;
118:...  
119:esac
120:done

Last edited by m2dmhot; 02-17-2010 at 10:39 AM.
 
Old 02-17-2010, 10:46 AM   #35
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 i went back to original script with the latest help..
still chokin near bottom line 118
./123456789_fedora11: line 118: syntax error near unexpected token `newline'
./123456789_fedora11: line 118: `... '


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"
108:...
109: case "$ANS" in
110:    "c" | "C" ) create_playlist ;;
111:    "e" | "E" ) edit_playlist ;;
112:    "d" | "D" ) delete_playlist ;;
113:    "g" | "G" ) generate_playlist ;;
114:    "p" | "P" ) play_mp3 ;;
115:    "o" | "O" ) copy_mp3 ;;
116:    "l" | "L" ) delete_mp3 ;;
117:    "q "| "Q" ) exit ;;
118:...  
119:esac
120:done
That's funny; running the above code (as lasted edited at 22:09) I got
Code:
c@CW8:~$ ./trash
./trash: line 58: syntax error near unexpected token `do'
./trash: line 58: `do'
Not surprising as there is no until, while or for line before the do.
 
Old 02-17-2010, 11:00 AM   #36
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
^
Code:
60:    cat "$AUDIOPATH"/tempdir.lst | while read line; do #Read each line of the file and store the line to $line variable
61:                                     ...
@m2dmhot: what is line 108 and line 118 supposed to do (they contain ...) ?
also 107 should be: echo debug: ANS = "$ANS"
you need to clean up these ellipsises
we use them to describe code that comes before or after but is not pertinent to the current issue.

Last edited by schneidz; 02-17-2010 at 11:40 AM.
 
Old 02-17-2010, 12:33 PM   #37
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by schneidz View Post
^
Code:
60:    cat "$AUDIOPATH"/tempdir.lst | while read line; do #Read each line of the file and store the line to $line variable
61:                                     ...
@m2dmhot: what is line 108 and line 118 supposed to do (they contain ...) ?
also 107 should be: echo debug: ANS = "$ANS"
you need to clean up these ellipsises
we use them to describe code that comes before or after but is not pertinent to the current issue.
Im not sure what those ... does i was told to change it in this post
http://www.linuxquestions.org/questi...69#post3866069
I fixed the echo also but not sure how to fix
Code:
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:}

Last edited by m2dmhot; 02-17-2010 at 12:39 PM.
 
Old 02-17-2010, 01:07 PM   #38
casperz
LQ Newbie
 
Registered: Feb 2010
Location: Ontario
Distribution: Mandriva, Fedora 11
Posts: 3

Rep: Reputation: 0
I have a question regarding this script....
When I run this script, create a playlist. I get a 0 bytes m3u file. (contains nothing)
I read somewhere that there was an issue with mplayer and m3u files??? Maybe it was an older posting..
I could just have is save it as a .txt file?
 
Old 02-17-2010, 01:18 PM   #39
casperz
LQ Newbie
 
Registered: Feb 2010
Location: Ontario
Distribution: Mandriva, Fedora 11
Posts: 3

Rep: Reputation: 0
find /home/woot/Mp3 -name "*.mp3" -print > playlist.txt

This will work.....only scans from the mp3 folder
 
Old 02-17-2010, 01:31 PM   #40
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
^ line 17 doesnt redirect ls -v to the file name therefore it remains blank. m2dmhot hasnt gotten that for because s/he got other errors to worry about first.

@m2dmhot
in Perl6, the 3-character ellipsis is also known as the "yadda yadda yadda" operator and, similarly to its linguistic meaning, serves as a "stand-in" for code to be inserted later.
http://en.wikipedia.org/wiki/Ellipsis

Last edited by schneidz; 02-17-2010 at 01:41 PM.
 
Old 02-17-2010, 01:34 PM   #41
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
ok i removed the '...' in both locations
now it gives me unexpected end of file syntax error
line 123

????
 
Old 02-17-2010, 01:52 PM   #42
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
hmm, thats interesting considering that the script has only 120 lines ?

maybe a blank line it doesnt like ?

possibly because exit isnt defined as a function so it doesnt know what to do (but i think it should exit from the shell so i am not sure) ?

Last edited by schneidz; 02-17-2010 at 02:06 PM.
 
Old 02-17-2010, 02:39 PM   #43
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by schneidz View Post
hmm, thats interesting considering that the script has only 120 lines ?

maybe a blank line it doesnt like ?

possibly because exit isnt defined as a function so it doesnt know what to do (but i think it should exit from the shell so i am not sure) ?
Seems like its me.. I got another fellow coder to run the script and it runs fine??? My bash version is 4.0.23 any ideas???
 
Old 02-17-2010, 03:01 PM   #44
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
it was the colons at the parts that were not filled in yet.. THanks guys i will finish this up and post back if any probs
 
Old 02-17-2010, 09:31 PM   #45
penguiniator
Member
 
Registered: Feb 2004
Location: Olympia, WA
Distribution: SolydK
Posts: 442
Blog Entries: 3

Rep: Reputation: 60
You should delete this code:
Code:
cat "$AUDIOPATH"/tempdir.lst |
from in front of your while loop. This code:
Code:
< "$AUDIOPATH"/tempdir.lst
at the end of the loop is meant to replace it.
 
  


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 08:16 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