[Sussex] BASH problem

Steve Dobson SDobson at manh.com
Mon Jul 14 12:14:00 UTC 2003


Geoff

On 14 July 2003 at 11:43 Geoff Teale wrote:
> Morning all..

Morning
 
> Just writing some bash script here this morning, what I need 
> is for the shell variable $IFS to store the return character
> (commonly represented by \n ).
> 
> However, using "\n" means that loops will now break on 
> instances of the letter 'n' (unfortunate to say the least).
> Putting in a literal return works but is very ugly to look at
> (see code snippet below):
> 
> tmp_IFS=$IFS
> #OK, OK, this is _dirty_ there is a literal return here :(
> IFS="
> "
> 
> ... Does anyone know of a neater way of doing this?

Why not use the printf command:

  tmp_IFS=`printf "\n"`

I've just read the man page for "echo" thinking you might
be able to do a:
   
  tmp_IFS="\022"

But it states that the printf method is more portable - not
that that's such a big issue for you but I still think the most
portable solution is the best.

Steve




More information about the Sussex mailing list