Correct Syntax for configuring IFS shell variable ?

Correct Syntax for configuring IFS shell variable ?

Post by Balraj Jassa » Tue, 31 Mar 1998 04:00:00



Hi,

I'm writing a ksh script and having a problem in setting up field
seperators whenever reading from strings / files. (I'm using SunOS5.5.1)

I'm performing a grep -w on an input file, and assuming a -w : word is
defined as anything being delimited by the IFS shell variable, I need it
to be able to handle a comma seperator as well as the original space,
new line and tab.

Does anyone know the correct syntax for setting up the IFS Shell
variable ?
And do I need to have root priviledges to set it up ?

Also, I'd be interested to know how to do the equivalent in csh.

Thanks in advance.

Balraj Jassal

 
 
 

Correct Syntax for configuring IFS shell variable ?

Post by Bob McGowa » Tue, 31 Mar 1998 04:00:00


The correct way of using the IFS variable would be:

ifs="$IFS"  # save the current value
IFS=",$IFS" # add a comma to the list of separators
.........   # your script
IFS="$ifs"    # restore the original

Any user can set their own IFS value, in scripts or otherwise.  Only
root would be able to set it on a global basis and that would be done by
setting it in the global profile /etc/profile.  I have no idea how csh
deals with input field separators or how they might be changed.

HOWEVER, this will do nothing for your stated problem.  Changing IFS
changes the way the SHELL parses input lines it gets via read, for
instance, or operations on variables.  IFS is NOT passed to grep so far
as I know (no mention anywhere in the manual or in any book on grep that
I have read).  What grep does is entirely up to grep and is not affected
by the IFS variable.

----
Bob McGowan
i'm bobmcgow at xstor dot com
Storage Dimensions, Inc.

-----Original Message-----

Posted At: Monday, March 30, 1998 3:02 AM
Posted To: shell
Conversation: Correct Syntax for configuring IFS shell variable ?
Subject: Correct Syntax for configuring IFS shell variable ?

Hi,

I'm writing a ksh script and having a problem in setting up field
seperators whenever reading from strings / files. (I'm using SunOS5.5.1)

I'm performing a grep -w on an input file, and assuming a -w : word is
defined as anything being delimited by the IFS shell variable, I need it
to be able to handle a comma seperator as well as the original space,
new line and tab.

Does anyone know the correct syntax for setting up the IFS Shell
variable ?
And do I need to have root priviledges to set it up ?

Also, I'd be interested to know how to do the equivalent in csh.

Thanks in advance.

Balraj Jassal


 
 
 

Correct Syntax for configuring IFS shell variable ?

Post by Christian Weisgerb » Tue, 31 Mar 1998 04:00:00




> I'm writing a ksh script and having a problem in setting up field
> seperators whenever reading from strings / files. (I'm using SunOS5.5.1)

> I'm performing a grep -w on an input file, and assuming a -w : word is
> defined as anything being delimited by the IFS shell variable,

On what do you base this assumption?
Typically, IFS only affects word splitting performed by the shell. It is
not used by any other programs. The grep on my machines, for example,
considers words to consist of letters, digits, and the underscore. (Of
course Solaris might be different.)

With that caveat...

Quote:> I need it to be able to handle a comma seperator as well as the
> original space, new line and tab.

IFS="$IFS,"

Quote:> Does anyone know the correct syntax for setting up the IFS Shell
> variable ?

Like any other shell variable, you simply assign a value to it.
Use the appropriate quoting to preserve white space and special
characters.

Quote:> And do I need to have root priviledges to set it up ?

Bizarre idea. No, of course you don't.

--

  See another pointless homepage at <URL:http://home.pages.de/~naddy/>.

 
 
 

Correct Syntax for configuring IFS shell variable ?

Post by bmar.. » Wed, 01 Apr 1998 04:00:00



   >Does anyone know the correct syntax for setting up the IFS Shell
   >variable ?
   >And do I need to have root priviledges to set it up ?
It's just like any other shell variable, you don't need root privileges.

Net-Tamer V 1.08X - Test Drive