Easy(?) problem for shell script writers
Scott Holt
scott at prism.gatech.EDU
Fri May 10 09:39:23 AEST 1991
In article <1991May9.151138.21246 at uvm.edu> moore at 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 at prism.gatech.edu
Georgia Tech UUCP: ..!gatech!prism!scott
Office of Information Technology, Technical Services
More information about the Comp.unix.aix
mailing list