bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Passing the results of GREP into a Bash Variable


From: Robert A. Adkins II
Subject: Re: Passing the results of GREP into a Bash Variable
Date: Thu, 12 Jul 2001 03:15:00 GMT

Okay,

     Would I write the script as thus?

    ps -e | GREPOUT=$(grep startx)

    I am assuming that this would make GREPOUT the variable name to use in the
if, then, else test.

    I will test the above to see if it works.

    Thanks for the help!
    Robert A. Adkins
    SeMI-LUG (at) bigfoot (dot) com


Chet Ramey wrote:

> >     I am working on a script that requires the result of a grep to be
> > piped or entered into a variable for an if, then, else check. Is that at
> > all possible?
>
> If you want the results that grep prints to the standard output, use
> command substitution:
>
> GREPOUT=$(grep ...)
>
> If you want the exit status of grep, use $?:
>
> grep ...
> GREPSTAT=$?
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
> ( ``Discere est Dolere'' -- chet)
>
> Chet Ramey, CWRU    chet@po.CWRU.Edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]