[ILUG-BOM] Using grep 'AND'

steve steve at lonetwin.net
Fri Mar 1 04:40:46 EST 2013


I know the question was answered, but ...

On Thursday 28 February 2013 01:18 AM, Osric Fernandes wrote:
> Hi Rony, Rajeev,
> [...snip...]
> A method that's both concise and readable is:
> home_mounted=`grep -w /home /etc/mtab`
> backup_mounted=`grep -w /backup /etc/mtab`
> if [ "$home_mounted" -a "$backup_mounted" ] ; then ...

Just FYI, a usual idiom for doing thing like this is simply:

grep -q "something" /some/where && \
grep -q "something else" /some/place/else && \

with this you can chain as many pre-conditions as you want, and the benefit is, 
if any one of the commands before the final one fails, the rest of the commands 
are not executed. This isn't a huge win in the specific scenario being 
discussed, but can significantly impact some scripts.


> Regards,
> Osric Xavier Fernandes
> PS: Great to have the mailing list back. Good job team!

More information about the Linuxers mailing list