Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!ucsd!ucbvax!ucsfcgl!maxwell.mmwb.ucsf.edu!rodgers From: rodgers@maxwell.mmwb.ucsf.edu (ROOT) Newsgroups: comp.unix.shell Subject: protecting whitespace from the Bourne "for" command Message-ID: <16570@cgl.ucsf.EDU> Date: 8 Dec 90 00:51:58 GMT Sender: daemon@cgl.ucsf.edu Reply-To: rodgers@maxwell.mmwb.ucsf.edu (ROOT) Organization: Univ. of Calif., San Francisco Lines: 42 Dear Netlanders, Does anyone know how to protect whitespace in items to be passed to the "for" operator of the Bourne shell? Consider the script: #! /bin/sh # # Define list # list="'a b' c" # # Use list # for item in $list do grep $item inputfile done # # Script complete where "inputfile" might contain, for example: a b c d The idea is to grep for each of the regular expressions appearing in $list, one at a time, in the file "inputfile". In the above example, "a b" is meant to comprise one such pattern, and "c" another. I have tried all sorts of combinations of \, ', and " in the definition of "list" and in the appearance of "$list" on the "for" command line, in an attempt to prevent the shell from parsing arguments on the whitespace contained within the the expr "a b", all to no avail. One such combination of failed quoting mechanisms is displayed above. Please, no responses of the form "why do you want to do this," "use perl," "use awk," etc. The above boils down the essence of a problem which appears in quite a different context. Any ideas???? Thanks and Cheerio, Rick Rodgers