Re: Using stupid filenames in shell scripts
On Thursday 15 May 2003 14:59, Robert Ian Smit wrote:
> I have copied some mp3 containing directories from a windows
> partition. In the days I created those files it seemed like a good
> idea to use filenames such as:
>
> 01 - Artist - Song1.mp3
> 02 - Artist - Song2.mp3
> etc.
> [...]
> For instance, I'd use something like:
>
> for i in `ls`; do echo $i; done
>
> This doesn't work properly. $i gets a lot of values like 01, -,
> Artist, Song.mp3 instead of one value per file.
Depending on what exactly you're trying to do, you could use find.
find -name "*.mp3" -exec echo {} ";"
would do what you wanted your example to do. Essentially, everything after the
-exec parameter is used as a command, {} substitutes the filename. The ";"
marks the end of the command (quoted to hide it from the ever watching
shell).
Other fun stuff would include xargs, sed and all those funny tools, but try to
keep it simple to avoid severe braindump ;-)
--
Got Backup?
Reply to: