Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!exodus!ichthous.Eng.Sun.COM!mcgrew From: mcgrew@ichthous.Eng.Sun.COM (Darin McGrew) Newsgroups: comp.unix.shell Subject: Re: protecting whitespace from the Bourne "for" command Message-ID: <4198@exodus.Eng.Sun.COM> Date: 8 Dec 90 02:23:17 GMT References: <16570@cgl.ucsf.EDU> Sender: news@exodus.Eng.Sun.COM Organization: Sun Microsystems, Mt. View, Ca. Lines: 39 In article <16570@cgl.ucsf.EDU> rodgers@maxwell.mmwb.ucsf.edu (ROOT) writes: >Does anyone know how to protect whitespace in items to be passed to the >"for" operator of the Bourne shell? Consider the script: Use `eval` so that the quotes are evaluated as such. Here's the revised script-- #! /bin/sh # # Define list # list="'a b' c" # # Use list # eval for item in "$list" \; \ do \ grep \"\$item\" inputfile \; \ done # # Script complete Yes, getting the quoting right can be difficult if the body of the loop is large. Another option might be to have a small loop that feeds a `while read foo` loop-- eval for item in $list \; \ do \ echo \"\$item\" \; \ done | while read item do grep "$item" inputfile # More big, hairy, loop that would be too # confusing with '\' characters everywhere done Darin McGrew mcgrew@Eng.Sun.COM Affiliation stated for identification purposes only.