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.
You don't need basename in the shell, just use stripping. FILE="${f%.*}".wav % strips shortest matching suffix, %% longest, # shortest matching prefix, ## longest. So ${f##*.} gets you the suffix, ${f%/*} gets the dirname, etc. And since you're not preserving the value of FILE for anything, just do it: do lame "${f%.*}".wav; done.
What you were looking for is useful other times, though, and it's called "command substitution" in the manpage. Do it with $() (<-parens instead of curlies) or backticks. $(basename "$f").
"basename" has nothing to do with extensions. It simply returns the last item in a slash-separated path (i.e. get the actual name of the file from a path). Similarly, "dirname" returns the path, removing the filename from the end.
And just in case you didn't know, Linux or its filesystems has no concept of extensions. Some programs do pay attention to them, though (most notably GUI file maangers, to tell the type of file, becasue it's faster to read the file's name than open in and look throught it to figure out its contents).
I don't really understand that thread. Is the trouble about spacing between arguments or in filenames? And isn't it bash that has trouble with spaces, not the program launched?
I don't really understand that thread. Is the trouble about spacing between arguments or in filenames? And isn't it bash that has trouble with spaces, not the program launched?
The problem seems to be blank spaces in file names. I tried using basename to convert the extensions from wav to mp3.
Code:
for i in *.wav ; do
echo $i
b=`basename $i .wav`
lame -V $i $b.mp3
done
I ended up with a screen full of "excess arg" errors. Lame would consider any name up to the first blank space to be one argument. It could be a shell problem. Probably the escape characters get stripped out of the file names. Anyway I tracked down that thread, and their little copy and paste command worked. Since the OP's real problem was wanting to convert wav files to mp3 files, I thought I would pass it on.
DIdn't I already say that basename has nothing to do with extensions?!? Just scroll up to the 3rd post.
And it's the shell that splits filenames with spaces into separate arguments. To stop it from splitting the contents if a variable into multiple args, surround it in double-quotes (i.e. "$i").
DIdn't I already say that basename has nothing to do with extensions?!? Just scroll up to the 3rd post.
And it's the shell that splits filenames with spaces into separate arguments. To stop it from splitting the contents if a variable into multiple args, surround it in double-quotes (i.e. "$i").
You da man. I think I will go listen to some mp3s.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.