Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 ...
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 10:06 PM.
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.
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
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.
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.
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.
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??
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.
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
}
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'
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.