On 27 February 2013 10:41, Binand Sethumadhavan <[email protected]> wrote: > On 26 February 2013 23:45, [email protected] <[email protected]> > wrote: >> 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. > > How about: > > if [ $( grep -cE '/(home|backup)' /etc/mtab ) = 2 ]; then > echo Found both mounts > else > echo Found only one of the two mounts > fi > > (Refine as per your needs) >
Fails for Case where mount points /home and /home_new exist. Still get count 2 with no backup. In addition, if i have /backup mounted too, the script would actually fail, since the count now becomes 3 ! :-P Regards R. K. Rajeev > Binand > -- > http://mm.ilug-bom.org.in/mailman/listinfo/linuxers -- http://mm.ilug-bom.org.in/mailman/listinfo/linuxers

