[ILUG-BOM] Using grep 'AND'

Binand Sethumadhavan binand at gmail.com
Wed Feb 27 00:28:21 EST 2013


On 27 February 2013 10:52, Rajeev R. K. <rajeevrk at xlncenterprises.com> wrote:
>> 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,

Come on man, that's why I specifically mentioned "refine to your
needs". If I were to refine this for Rony's needs as he articulated,
I'd write that regex as:

'^[^[:space:]]*[[:space:]]/(home|backup)[[:space:]]'

Which covers all the special cases you mention and some more.

Binand


More information about the Linuxers mailing list