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.
You seem to be missing the last line in penguiniators post #53
Evo2.
Na somethings not right now its not working anymore
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
done
}
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
done < "$AUDIOPATH"/tempdir.lst
rm "$AUDIOPATH"/tempdir.lst # Delete the temporary file containing the directory listing
}
OK that worked great.. Now one more touch i would like to add to my script is it at all possible to assign the results when it list the mp3 or m3u as a # or letter variable so i can select it instead of typing in the full name (more chance of user error) ????
When you do the `ls` command to create the temporary file, I would pipe that `ls` through a `cat -n` in order to produce a line number at the start of each line. Do the same thing with the second `ls` command which presents the list to the user.
Now, when the user inputs an item for selection (for copying) you will need to perform some checking of the input, to see whether or not is it a number, or a title; in other words, $DONKEY will end up being either "a number", or a text string ending with ".mp3" (and if it's neither of these, quit with an error).
If it's a text-string.mp3, then proceed as you currently are doing, though you'll need to account for the line numbers in the temp file. If it's a NUMBER, then you'd need to parse the temporary file to locate the line number matching the number entered, and grab the filename.
This would be rather easy, using maybe `awk` to parse the temporary file to read the filename from the correct line, however it is less easy than it could be, because of the spaces in the filenames. However, this can be worked around by simply finding the correct line of the temp file (by line number) and using `sed` to prune off the first field (which will be the line number, including the space following the line number) and presto -- there's your filename.
Anyhow, this is where I'd start. May sound complex, but not really too too complex; though I realize, this is early in your scripting experience, so one thing at a time.. The first thing I'd do, if I were you and you want to go this route that I've described, is read the man page for cat, and then try adding the pipe and cat command to the `ls` commands you already have. We'll see where to go from there.
Sasha
Last edited by GrapefruiTgirl; 02-17-2010 at 11:35 PM.
my newest task with this script is to remove the path in the playlist without actually modifying the file
PLAYLIST=/home/woot
AUDIOPATH=$PLAYLIST/MP3
Code:
view_playlist() {
cd "$PLAYLIST"
ls -v *.m3u
echo -e
echo -e "Please Type In The Playlist You Wish To View --> \c"
IFS= read M3UTOPLAY
cat $PLAYLIST/$M3UTOPLAY
}
when i run this code it shows the full path. Is there anyway to to show the contents of the file without the full path
example
instead of /home/woot/blablabla.mp3
blablabla.mp3
i think its with the sed cmd but unsure how to do it???
When you do the `ls` command to create the temporary file, I would pipe that `ls` through a `cat -n` in order to produce a line number at the start of each line. Do the same thing with the second `ls` command which presents the list to the user.
Now, when the user inputs an item for selection (for copying) you will need to perform some checking of the input, to see whether or not is it a number, or a title; in other words, $DONKEY will end up being either "a number", or a text string ending with ".mp3" (and if it's neither of these, quit with an error).
If it's a text-string.mp3, then proceed as you currently are doing, though you'll need to account for the line numbers in the temp file. If it's a NUMBER, then you'd need to parse the temporary file to locate the line number matching the number entered, and grab the filename.
This would be rather easy, using maybe `awk` to parse the temporary file to read the filename from the correct line, however it is less easy than it could be, because of the spaces in the filenames. However, this can be worked around by simply finding the correct line of the temp file (by line number) and using `sed` to prune off the first field (which will be the line number, including the space following the line number) and presto -- there's your filename.
Anyhow, this is where I'd start. May sound complex, but not really too too complex; though I realize, this is early in your scripting experience, so one thing at a time.. The first thing I'd do, if I were you and you want to go this route that I've described, is read the man page for cat, and then try adding the pipe and cat command to the `ls` commands you already have. We'll see where to go from there.
Sasha
on the right track here
Code:
cd "$AUDIOPATH"
ls -v *.mp3 > "$AUDIOPATH"/tempmp3.lst # Create Temp file with Directory listing in sequence
cat -n "$AUDIOPATH"/tempmp3.lst > outputmp3.lst
cat outputmp3.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.