[ILUG-BOM] Using grep 'AND'

Rajeev R. K. rajeevrk at xlncenterprises.com
Tue Feb 26 14:36:51 EST 2013

Here you go.....

mount | grep -q home
mount | grep -q backup

if [ $HOMESTATUS -eq 0 -a $BACKUPSTATUS -eq 0 ]; then
        echo "You got both man, do your thing..."
        exit 0;
       echo "Error -- either home or backup missing -- Or is it BOTH !%$!!@#%!"
       exit 1;

R. K. Rajeev

P.S. : Dont rely too much on mtab, a read only filesystem situation
might mean you have old/stale data in it, always pipe live mount
command or use /proc/mounts.

On 26 February 2013 23:45, gnulinuxist at gmail.com <gnulinuxist at gmail.com> wrote:
> Hello,
> I am using a script where I check if /home and /backup are present in /etc/mtab but can't manage the 'and' operator in grep. Currently I use the 'if grep -q "/home" ; then .........  then I do 'fi' and again 'if grep -q "/backup" to finally go to my commands. I tried to make grep do the AND combo but got errors as it works only on one line. I want my command to start only if both /home and /backup are present in mtab. With my dual check method it works, but I want a clean lean script.
> Regards,
> Rony.
> --
> http://mm.ilug-bom.org.in/mailman/listinfo/linuxers

More information about the Linuxers mailing list