Newsgroups: comp.unix.shell
Path: utzoo!utgpu!watserv1!watmath!mks.com!mks!eric
From: eric@mks.mks.com (Eric Gisin)
Subject: Re: why does sh do this
Sender: eric@mks.com (Eric Gisin)
References: <1991Jun4.074041.5300@cs.uow.edu.au>
In-Reply-To: pdg@cs.uow.edu.au's message of 4 Jun 91 07:40:41 GMT
Organization: Mortice Kern Systems Inc., Waterloo, Ontario, CANADA
Date: 4 Jun 91 13:41:36
Message-ID: <ERIC.91Jun4134136@mks.mks.com>

In article <1991Jun4.074041.5300@cs.uow.edu.au> pdg@cs.uow.edu.au (Peter Gray) writes:
   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.

---

Right on the first page of sh(1) it says [a command is a list of
words separated by spaces or tabs]. When the script is
read, commands are split into a list of words. This is necessary
so the keywords, assignments, and regular words can be determined.
IFS is used for further splitting when the script is executed.

For example:
	cmd="ls fred jim"
	IFS=" "
	"$cmd"			# one word, "" prevents splitting
	$cmd			# three words, runs ls
	IFS=":"
	$cmd			# one word, does not run ls
