Re: [SLUG] Bash Problem - SOLVED

From: Paul M Foster (paulf@quillandmouse.com)
Date: Thu Aug 07 2003 - 02:07:35 EDT


On Thu, Aug 07, 2003 at 12:38:49AM -0400, Paul M Foster wrote:

> Within a bash script, I'm trying to feed each line of a file into a
> variable, to wit:
>
> for line in `cat file`
> do
> do_whatever
> done
>
> At the end of this operation, I want the $line variable to equal the
> contents of a single line in the file. The problem is that the shell
> breaks the line into _words_ if there are any spaces, tabs or newlines
> in it. I understand why. It's because of the value of the IFS shell
> variable. To get around this, I want to set the IFS variable to be
> _only_ the newline. But I can't find a way to do it. The following do
> not work:
>
> IFS=
>
> IFS=\n
> IFS='\n'
> IFS="\n"

The answer (to set IFS to only a newline) is:

IFS='
'

Paul
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 16:12:51 EDT