On 26 February 2013 23:45, gnulinuxist@gmail.com gnulinuxist@gmail.com 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)
Binand