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

Re: Bash question



On Tue, Jul 01, 2003 at 07:43:28AM -0600, Jamin W. Collins wrote:
> On Tue, Jul 01, 2003 at 02:46:58AM -0500, Stephan Sauerburger wrote:
> > 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?
> 
> This has been asked and answered a few times in the past.  There are
> several ways to do it.  Here is one:
> 
>    #!/bin/sh
>    IFS=$'\n'
> 
>    for FILE in `ls -1`; do
>       echo $FILE
>    done

FYI, Unix filenames are allowed to contain newlines.

-- 
Colin Watson                                  [cjwatson@flatline.org.uk]



Reply to: