Click to See Complete Forum and Search --> : Shell: Finding a file in current directory


Sastraxi
08-11-2002, 11:48 AM
I need a command that finds a file in the current directory (doesn't matter which) and follows a pattern, eg. ff *.mp3. I'm trying to make a shell script that mpg123 then oggenc's all the Mp3s in a directory.

LoKe137
08-11-2002, 11:53 AM
I think it is the command "which" you are looking for, If I got the question right. This is one of my first answer post, ehhehe

Also look at www.google.com/linux for linux command or errors help

Sastraxi
08-11-2002, 03:18 PM
No, I found it, by doing a for loop in: 'files in $1/*.mp3'. However, it doesn't like long filenames. ALso, how can I take off the mp3 of a string and put on a wav? I need to find the same name of it when it's a wav. Also, how do you handle long filenames in bash?

dfx
08-11-2002, 03:49 PM
By saying "long filenames" I assume you mean filenames with spaces. Actually the for loop (and bash in general) can handle such filenames perfectly, you just need to use quotes in the right places. As for removing a filename suffix, the basename prog can do that, but it removes a leading path as well, so you gotta be careful. A script that does what you want could look like:


for file in "$1"/*.mp3
do
filebase="$1"/"$(basename "$file" .mp3)"
mpg123 -w "$filebase".wav "$file"
oggenc -o "$filebase".ogg "$filebase".wav
done


If the .wav is just temporary, you can add an rm in there, of even eliminate the file completely by piping mpg123 and oggenc together.

Sastraxi
08-11-2002, 04:51 PM
After I made this (it looks nearly exactly like your code, though I just didn't try for the spaces), I read up on piping. Cool nuts. Also, whenever I use if or echo commands, it gives me syntax error near token 'if' (there's a adjective that describes token but I don't want to edit it again).

This stuff is really cool, thanks for your help.

I think my next script will be a thing that can link decoders/encoders by checking the end of the file and piping the right decoders :)

In fact... I think I'll do that now :cool:

Thanks again.