Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!munnari.oz.au!metro!cs.uow.edu.au!pdg From: pdg@cs.uow.edu.au (Peter Gray) Newsgroups: comp.unix.shell Subject: why does sh do this Summary: sh vs man sh Keywords: sh, IFS Message-ID: <1991Jun4.074041.5300@cs.uow.edu.au> Date: 4 Jun 91 07:40:41 GMT Organization: Dept of Computer Science, Wollongong University, Australia Lines: 46 I have a question regarding sh and IFS. From my reading of the man page for sh the following script should not work. #!/bin/sh IFS=":"; export IFS echo fred ls fred jim My understanding is the shell should be looking for commands "echo fred" and "ls fred jim". But it works fine. On the ls command fred and jim are treated as 2 arguments. On the other hand the shell builtins seem to use the IFS as documented. EG echo "fred:jim jack:mary" | (IFS=":"; read a b c; echo "$a\n$b\$c") produces fred jim jack mary The SUNOS man page for sh says After parameter and command substitution, the results of substitution are scanned for internal field separator char- acters (those found in IFS) and split into distinct argu- ments where such characters are found. Explicit null argu- ments ("" or '') are retained. Implicit null arguments (those resulting from parameters that have no values) are removed. How does sh actually use IFS??? Why doesn't altering IFS alter the interpretation of subsequent lines in a script? pdg Peter Gray Internet: pdg@draci.cs.uow.EDU.AU Professional Officer UUCP: ...!munnari!draci.cs.uow.EDU.AU!pdg Dept of Computer Science MHSnet: pdg@draci.cs.uow.oz.au University of Wollongong Phone: +61 42 213770 N.S.W. 2500 Australia Fax : +61 42 213262