ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
I found a good script that converts wav files into mp3s. But I would like to know how to modify it so that it does each wav file one by one in a directory until they are all done. Right now I am having to copy each wav file to a new directory and running the script. I will post the script below and if someone could help I would appreciate it.
Code:
#!/bin/bash
#
# wav2mp3
#
for i in *.wav; do
#out=$(ls $i | sed -e 's/.wav//g')
#out=$(echo $i | sed -e 's/.wav$//')
#lame -h -b 96 "$i" "$out.mp3"
lame -h -b 96 "$i" "${i%.wav}.mp3"
done
#!/bin/bash
#
# wav2mp3
#
# The directory to export .mp3 files to is passed as argument 1
# The script should be invoked as wav2mp3 new_dir/
# If there is no argument, a default value is used.
# If the directory doesn't exist, then it is created if the user has enough permissions
#
EXPORT_DIR=
if [ $# -eq 0 ]; then
EXPORT_DIR="wav2mp3_out"
else
EXPORT_DIR="$1"
fi
if ! [ -d $EXPORT_DIR ]; then
mkdir -p $EXPORT_DIR
fi
# now EXPORT_DIR holds the directory to which to export the new files
for i in *.wav; do
lame -h -b 96 "$i" "$EXPORT_DIR/$i.mp3"
done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.