Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!haven!adm!xadmx!mchinni@pica.army.mil From: mchinni@pica.army.mil (Michael J. Chinni, SMCAR-CCS-E) Newsgroups: comp.unix.questions Subject: Re: Help with strings in Bourne shell Message-ID: <19311@adm.BRL.MIL> Date: 26 Apr 89 14:30:17 GMT Sender: news@adm.BRL.MIL Lines: 38 Jim Rudolf writes: > If I have a Bourne script called 'foo' and I call it with the arguments: > foo "color = red" "size = big" > then from within foo they will be read as: > $1 = "color = red" > $2 = "size = big" > However, I want to read from stdin (or maybe a redirected pipe), and I > can't get it to work no matter what strange combination of quotes I use! > I would like to do something like: > read args > for i in $args > . > . > so I can process each string in turn. Why can't I get this to work? > Do command line arguments get treated differently than arguments read > from within the script? Any suggestions would be greatly appreciated. As to how to do this, others have given answers. As to why this doesn't work, read on. The problem is with the "for" loop. The "for" construct uses a list of arguments which are words separated by tabs/spaces. Therefore, "for" will split your arguments into their individual words. Given your command line arguments: echo $1 echo $2 will produce color = red size = big I know of no way to do what you want using a "for" loop. /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ Michael J. Chinni Chief Scientist, Simulation Techniques and Workplace Automation Team US Army Armament Research, Development, and Engineering Center User to skeleton sitting at cobweb () Picatinny Arsenal, New Jersey and dust covered terminal and desk () ARPA: mchinni@pica.army.mil "System been down long?" () UUCP: ...!uunet!pica.army.mil!mchinni /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/