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

Re: Bash question



Use either ls -b (quote nongraphic characters) or ls -Q (enclose in double
quotes) for passing the files to the shell.

ap

----------------------------------------------------------------------
Andrew J Perrin - http://www.unc.edu/~aperrin
Assistant Professor of Sociology, U of North Carolina, Chapel Hill
clists@perrin.socsci.unc.edu * andrew_perrin (at) unc.edu


On Tue, 1 Jul 2003, Stephan Sauerburger wrote:

> This is a general shell-scripting question:
>
> In a for loop which runs through all files, as in:
>
> for file in `ls`
> do
>   #stuff
> done
>
> How do I have it make sure it iterates file-by-file? The following example, to play all
> mp3s in the current directory:
>
> for file in `ls`
> do
>   mpg123 $file
> done
>
> ...will do just a fine job, so long as none of the file names have any
> spaces in them. If my directory contained:
>
> Aerosmith - Walk This Way.mp3
> (They Might Be Giants) - Istanbul.mp3
> Pink Floyd - The Wall.mp3
>
> 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".
>
> So how can one have the for loop separate the elements of the list only by
> newlines ("\n"), filling the contents of "file" with the whole line,
> and not separate by spaces, tabs, or other white space?
>
> Thx,
>
> --
> Stephan
>
>
> --
> To UNSUBSCRIBE, email to debian-user-request@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
>
>



Reply to: