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

Original Poster
Rep: Reputation: 15

Quote:
Originally Posted by penguiniator View Post
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.

still stuck
Code:
copy_mp3() { 
   
    cd "$AUDIOPATH"
    ls -v *.mp3 >> "$AUDIOPATH"/tempdir.lst # Create Temp file with Directory listing

    cd "$AUDIOPATH"
    ls -v *.mp3
    echo -e 

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

    < "$AUDIOPATH"/tempdir.lst | while read line; do #Read each line of the file and store the line to $line variable
                                     ...
                                    done < "$AUDIOPATH"/tempdir.lst
        if [ "$line" = "$DONKEY" ]; then
            echo "File Already Exist, Copy Aborted!"
        else
            cp $DONKEY "$PLAYLIST"
       fi
     
     rm "$AUDIOPATH"/tempdir.lst # Delete the temporary file containing the directory listing

}
Everyone tells me to remove the ... so i do then the script wont run.
I guess cause its missing soemthing.. But then when i run as is runs but then chokes when i do the copy option cause of the ...
 
Old 02-17-2010, 11:04 PM   #47
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Code:
copy_mp3() { 
   
    cd "$AUDIOPATH"
    ls -v *.mp3 >> "$AUDIOPATH"/tempdir.lst # Create Temp file with Directory listing

    cd "$AUDIOPATH"
    ls -v *.mp3
    echo -e 

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

    < "$AUDIOPATH"/tempdir.lst | while read line; do #Read each line of the file and store the line to $line variable
                                     ...
                                    done < "$AUDIOPATH"/tempdir.lst
        if [ "$line" = "$DONKEY" ]; then
            echo "File Already Exist, Copy Aborted!"
        else
            cp $DONKEY "$PLAYLIST"
       fi
     
     rm "$AUDIOPATH"/tempdir.lst # Delete the temporary file containing the directory listing

}
Remove the stuff I put in bold, and also, remove those three dots -- they were just used to indicate "stuff", like this:
Code:
echo "hi, this is line 1"
echo "hi, line 2 here"
...
echo "line 100 here!"
See? I used the '...' to indicate that there's "stuff" in there.

Plus, it looks to me like you would end up with an empty while-do loop; maybe the "done" should be moved down to near the end of the file.
I'm going over the whole thread now -- I haven't yet read it. I'll give more feedback in a moment.


Sasha

Last edited by GrapefruiTgirl; 02-17-2010 at 11:06 PM.
 
Old 02-17-2010, 11:10 PM   #48
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Code:
copy_mp3() { 
   
    cd "$AUDIOPATH"
    ls -v *.mp3 >> "$AUDIOPATH"/tempdir.lst # Create Temp file with Directory listing

    cd "$AUDIOPATH"
    ls -v *.mp3
    echo -e 

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

while read line; do
                              
        if [ "$line" = "$DONKEY" ]; then
            echo "File Already Exist, Copy Aborted!"
        else
            cp $DONKEY "$PLAYLIST"
       fi
     
     rm "$AUDIOPATH"/tempdir.lst # Delete the temporary file containing the directory listing

done < "$AUDIOPATH"/tempdir.lst
}
OK, this looks a little better. The tempdir.lst file gets catted into the while-do-done loop, and the loop performs the "stuff" between the WHILE and DONE lines, for each item encountered from the catted list.

Make sense?

If this still produces some error, post the output from running it.

Sasha
 
Old 02-17-2010, 11:18 PM   #49
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
[QUOTE=GrapefruiTgirl;3867619]
Code:
copy_mp3() { 
   
    cd "$AUDIOPATH"
    ls -v *.mp3 >> "$AUDIOPATH"/tempdir.lst # Create Temp file with Directory listing

    cd "$AUDIOPATH"
    ls -v *.mp3
    echo -e 

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

while read line; do
                              
        if [ "$line" = "$DONKEY" ]; then
            echo "File Already Exist, Copy Aborted!"
        else
            cp $DONKEY "$PLAYLIST"
       fi
     
     rm "$AUDIOPATH"/tempdir.lst # Delete the temporary file containing the directory listing

done < "$AUDIOPATH"/tempdir.lst
}
OK, this looks a little better. The tempdir.lst file gets catted into the while-do-done loop, and the loop performs the "stuff" between the WHILE and DONE lines, for each item encountered from the catted list.

Make sense?

Im starting to learn yes but still givin me probs
Code:
[root@localhost woot]# ./123456789_woot 



Mp3 Playlist Program:
================================
A)Create Mp3 Playlist
B)View Mp3 Playlists
C)Play Mp3 Playlist
D)Add Mp3 To Playlist
E)Remove Mp3 From Playlist
F)Clear Mp3 Playlist
G)Generate Mp3 Database
H)Play Mp3
I)Copy Mp3
J)Delete Mp3
Q)Quit
Enter your selection ==> i
01-inna_-_hot_(play_and_win_radio_version).mp3
01-pitbull_feat._nicole_scherzinger-hotel_room_service_(126_bpm)_(remixed_by_dj_absinth)-umt.mp3
02-kesha--tik_tok_(tom_nevilles_crunk_and_med_vocal_mix)-wus.mp3
03-medina-you_and_i_(spencer_and_hill_remix).mp3
DJ Antoine - Underneath (Radio Mix).mp3
Deepest Blue - Give It Away (Radio Edit).mp3
Energy Club House - Justin Dohman 1.mp3
Public Domain - Operation Blade 2009 (Radio Edit).mp3
Rockefeller - Do It 2 Nite (Radio Edit).mp3
The Kic Pimpz - No Stopping Us (Radio Edit).mp3

Please Select Your Song To Copy --> The Kic Pimpz - No Stopping Us (Radio Edit).mp3
cp: cannot stat `The': No such file or directory
cp: cannot stat `Kic': No such file or directory
cp: cannot stat `Pimpz': No such file or directory
cp: cannot stat `-': No such file or directory
cp: cannot stat `No': No such file or directory
cp: cannot stat `Stopping': No such file or directory
cp: cannot stat `Us': No such file or directory
cp: cannot stat `(Radio': No such file or directory
cp: cannot stat `Edit).mp3': No such file or directory
cp: cannot stat `The': No such file or directory
cp: cannot stat `Kic': No such file or directory
cp: cannot stat `Pimpz': No such file or directory
cp: cannot stat `-': No such file or directory
cp: cannot stat `No': No such file or directory
cp: cannot stat `Stopping': No such file or directory
cp: cannot stat `Us': No such file or directory
cp: cannot stat `(Radio': No such file or directory
cp: cannot stat `Edit).mp3': No such file or directory
rm: cannot remove `/home/woot/MP3/tempdir.lst': No such file or directory
cp: cannot stat `The': No such file or directory
cp: cannot stat `Kic': No such file or directory
cp: cannot stat `Pimpz': No such file or directory
cp: cannot stat `-': No such file or directory
cp: cannot stat `No': No such file or directory
cp: cannot stat `Stopping': No such file or directory
cp: cannot stat `Us': No such file or directory
cp: cannot stat `(Radio': No such file or directory
cp: cannot stat `Edit).mp3': No such file or directory
rm: cannot remove `/home/woot/MP3/tempdir.lst': No such file or directory
cp: cannot stat `The': No such file or directory
cp: cannot stat `Kic': No such file or directory
cp: cannot stat `Pimpz': No such file or directory
cp: cannot stat `-': No such file or directory
cp: cannot stat `No': No such file or directory
cp: cannot stat `Stopping': No such file or directory
cp: cannot stat `Us': No such file or directory
cp: cannot stat `(Radio': No such file or directory
cp: cannot stat `Edit).mp3': No such file or directory
rm: cannot remove `/home/woot/MP3/tempdir.lst': No such file or directory
cp: cannot stat `The': No such file or directory
cp: cannot stat `Kic': No such file or directory
cp: cannot stat `Pimpz': No such file or directory
cp: cannot stat `-': No such file or directory
cp: cannot stat `No': No such file or directory
cp: cannot stat `Stopping': No such file or directory
cp: cannot stat `Us': No such file or directory
cp: cannot stat `(Radio': No such file or directory
cp: cannot stat `Edit).mp3': No such file or directory
rm: cannot remove `/home/woot/MP3/tempdir.lst': No such file or directory
cp: cannot stat `The': No such file or directory
cp: cannot stat `Kic': No such file or directory
cp: cannot stat `Pimpz': No such file or directory
cp: cannot stat `-': No such file or directory
cp: cannot stat `No': No such file or directory
cp: cannot stat `Stopping': No such file or directory
cp: cannot stat `Us': No such file or directory
cp: cannot stat `(Radio': No such file or directory
cp: cannot stat `Edit).mp3': No such file or directory
rm: cannot remove `/home/woot/MP3/tempdir.lst': No such file or directory
cp: cannot stat `The': No such file or directory
cp: cannot stat `Kic': No such file or directory
cp: cannot stat `Pimpz': No such file or directory
cp: cannot stat `-': No such file or directory
cp: cannot stat `No': No such file or directory
cp: cannot stat `Stopping': No such file or directory
cp: cannot stat `Us': No such file or directory
cp: cannot stat `(Radio': No such file or directory
cp: cannot stat `Edit).mp3': No such file or directory
rm: cannot remove `/home/woot/MP3/tempdir.lst': No such file or directory
cp: cannot stat `The': No such file or directory
cp: cannot stat `Kic': No such file or directory
cp: cannot stat `Pimpz': No such file or directory
cp: cannot stat `-': No such file or directory
cp: cannot stat `No': No such file or directory
cp: cannot stat `Stopping': No such file or directory
cp: cannot stat `Us': No such file or directory
cp: cannot stat `(Radio': No such file or directory
cp: cannot stat `Edit).mp3': No such file or directory
rm: cannot remove `/home/woot/MP3/tempdir.lst': No such file or directory
cp: cannot stat `The': No such file or directory
cp: cannot stat `Kic': No such file or directory
cp: cannot stat `Pimpz': No such file or directory
cp: cannot stat `-': No such file or directory
cp: cannot stat `No': No such file or directory
cp: cannot stat `Stopping': No such file or directory
cp: cannot stat `Us': No such file or directory
cp: cannot stat `(Radio': No such file or directory
cp: cannot stat `Edit).mp3': No such file or directory
rm: cannot remove `/home/woot/MP3/tempdir.lst': No such file or directory
File Already Exist, Copy Aborted!
rm: cannot remove `/home/woot/MP3/tempdir.lst': No such file or directory
 
Old 02-17-2010, 11:21 PM   #50
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
You are suffering from "There's spaces in my filenames" syndrome.

Step #1 would be to put $DONKEY in quotes. However, to save yourself a lot of grief in the future, it's a good habit to get into to NOT use spaces in filenames.
 
Old 02-17-2010, 11:22 PM   #51
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by GrapefruiTgirl View Post
Plus, it looks to me like you would end up with an empty while-do loop;
You can use the true or : commands to "do nothing" and avoid empty do loops during development.
 
Old 02-17-2010, 11:25 PM   #52
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Oh -- I think I erred by putting the `rm` command inside the while loop; that should probably be put OUTSIDE the loop, otherwise (as we can see from the errors) the file is being removed far too early.

Sorry about that
 
Old 02-17-2010, 11:26 PM   #53
penguiniator
Member
 
Registered: Feb 2004
Location: Olympia, WA
Distribution: SolydK
Posts: 442
Blog Entries: 3

Rep: Reputation: 60
Code:
while read line; do                     
    if [ "$line" = "$DONKEY" ]; then
        echo "File Already Exist, Copy Aborted!"
    else
        cp $DONKEY "$PLAYLIST"
    fi
    rm "$AUDIOPATH"/tempdir.lst # Delete the temporary file containing the directory listing
done < "$AUDIOPATH"/tempdir.lst
One problem with the loop above is the rm line. It will delete the input file after the first line is read. That line of code needs to be moved below the while loop.
 
Old 02-17-2010, 11:26 PM   #54
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Quote:
Originally Posted by catkin View Post
You can use the true or : commands to "do nothing" and avoid empty do loops during development.
Sure but why would we have wanted a do-nothing loop here? Nothing would get done
 
Old 02-17-2010, 11:27 PM   #55
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by GrapefruiTgirl View Post
You are suffering from "There's spaces in my filenames" syndrome.

Step #1 would be to put $DONKEY in quotes. However, to save yourself a lot of grief in the future, it's a good habit to get into to NOT use spaces in filenames.
I should of known better my play option has that..
Ok it works copy was aborted since file exists. But i look in the mp3 folder and the tmp file is not there how come its not creating one?? Does it even need that line??
 
Old 02-17-2010, 11:29 PM   #56
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
It IS creating the temp file, on line 2 of the function.

The temp file is removed later, using the `rm` command, on the last line of the function. If you want to verify this, comment out the rm line near the end, and run the script once.
 
Old 02-17-2010, 11:38 PM   #57
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
ok im not sure how to close the end of that?? the loop that is without makin it error???

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

    cd "$AUDIOPATH"
    ls -v *.mp3
    echo -e 

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

while read line; do
                              
        if [ "$line" = "$DONKEY" ]; then
            echo "File Already Exist, Copy Aborted!"
        else
            cp "$DONKEY" "$PLAYLIST"
       fi
     
       < "$AUDIOPATH"/tempdir.lst

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

}

Last edited by m2dmhot; 02-17-2010 at 11:51 PM.
 
Old 02-18-2010, 12:03 AM   #58
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
You seem to be missing the last line in penguiniators post #53

Quote:
done < "$AUDIOPATH"/tempdir.lst
Evo2.

Last edited by evo2; 02-18-2010 at 12:05 AM.
 
Old 02-18-2010, 12:06 AM   #59
penguiniator
Member
 
Registered: Feb 2004
Location: Olympia, WA
Distribution: SolydK
Posts: 442
Blog Entries: 3

Rep: Reputation: 60
Now you have a new error... your while loop is not terminated with a done statement. It appears you deleted the word done from the line that reads: '< "$AUDIOPATH"/tempdir.lst'

it should read:
Code:
done < "$AUDIOPATH"/tempdir.lst
 
Old 02-18-2010, 12:08 AM   #60
penguiniator
Member
 
Registered: Feb 2004
Location: Olympia, WA
Distribution: SolydK
Posts: 442
Blog Entries: 3

Rep: Reputation: 60
Just out of curiosity... what text editor are you using to write your script?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 05:11 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 12:10 PM
[SOLVED] bash : getopts problem in bash script. angel115 Programming 2 03-02-2009 11:53 AM
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 07:00 AM
Bash script to create bash script jag7720 Programming 10 09-10-2007 08:01 PM


All times are GMT -5. The time now is 12:33 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration