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.
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.
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
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.
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
}
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
^ 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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.