[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bash question

Stephan Sauerburger <stephan@sauerburger.org> writes:

> In a for loop which runs through all files, as in:
> for file in `ls`
> do
>   #stuff
> done

ITYM 'for file in *'...

> ...will do just a fine job, so long as none of the file names have any
> spaces in them.

because it gets around this.  In general, you want to be careful if
you're dealing with files with spaces in their names, since the shell
will be enthusiastic about breaking words.

  for file in *.ogg; do
    ogg123 "$file"

(Since the double-quotes allow variable expansion, but force the
result to be a single "world" for shell purposes.)

> Then the preceding instructions first try to play "Aerosmith", then
> "-", then "Walk", then "This", then "Way.mp3", then "(They"... you get the
> idea. All of which fail, and this could lead to dangerous results if you're
> doing something other than mpg123 to it, like "rm", and there were also a
> file simply called "Aerosmith".

ISTR earlier versions of Mac OS X, which is built on top of some BSD,
having issues like this as well.

David Maze         dmaze@debian.org      http://people.debian.org/~dmaze/
"Theoretical politics is interesting.  Politicking should be illegal."
	-- Abra Mitchell

Reply to: