[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: Which tool, and how, to get partial string from file?



On Sat, Aug 21, 2004 at 10:16:26AM -0500, Kent West wrote:
> How do I test to make sure the name is in two files? Like so?
> 
> if ( ! grep -q '\<tuber\>' /etc/passwd ) or ( ! grep -q '\<tuber\>' 
> /etc/shadow )
> then
>  echo "Error: One or both files are missing 'tuber'" | mail root
>  exit 1
> fi

Almost. I'm pretty sure there is no 'or', you have to use ||.

if ( ! grep -q '\<tuber\>' /etc/passwd ) || ( ! grep -q '\<tuber\>' 
/etc/shadow )
then
   echo "Error: One or both files are missing 'tuber'" | mail root
   exit 1
fi

Note that the parens are probably unneccesary, but IMO they improve
readability.



Reply to: