Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!ncar!gatech!prism!scott From: scott@prism.gatech.EDU (Scott Holt) Newsgroups: comp.unix.aix Subject: Re: Easy(?) problem for shell script writers Message-ID: <28614@hydra.gatech.EDU> Date: 9 May 91 23:39:23 GMT References: <1991May9.151138.21246@uvm.edu> Organization: Georgia Institute of Technology Lines: 54 In article <1991May9.151138.21246@uvm.edu> moore@emily.uvm.edu (Bryan Moore) writes: >I am trying to write a shell script (AIX 3.1 ksh) that does the following, >takes the output from an (awk) command, say > >STRING1 >STRING2 >STRING3 > >and use each of those strings as a parameter to the fgrep of >a system call. > >I want to do a 'ps | fgrep $1' where $1 is each of the above >strings, but obviously the above is incorrect. > >There must be an easy way to do this. I hope my explanation >is understandable. sounds like you want something to the effect of: PARAMETERS=`awk ...` - those are accent characters if [ "$PARAMETERS" ] then for i in $PARAMETERS do ps | fgrep $i done else echo "Awk found nothing" fi the first part is called a command substitution - the command in the accent characters is executed and the variable (PARAMETERS in this case) is set to its standard output. The if statement is a check just to make sure awk found something; it makes sure PARAMETERS is not the null string. > >If I should be posting this to another group, let me know ( I'm >sure someone will!). yup - I think this is probably a better question for comp.unix.questions or comp.unix.shell. If you really want to dive into this kind of stuff, I would check out the following books: The Korn Shell Command and Programming Language - Bolsky and Korn or UNIX Shell Porgramming - Revised Edition - Kochan and Wood - Scott -- This is my signature. There are many like it, but this one is mine. Scott Holt Internet: scott@prism.gatech.edu Georgia Tech UUCP: ..!gatech!prism!scott Office of Information Technology, Technical Services