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

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



Stefan O'Rear wrote:

On Fri, Aug 20, 2004 at 09:46:52PM -0500, Kent West wrote:
Maybe I'm asking the wrong question.

Here's a new question.

How can I test to see if the word "tuber" is in the /etc/passwd file, reliably, and take an action if it is, and take a different action if it's not, in a bash shell script?

if grep -q '\<tuber\>' /etc/passwd
then
  echo 'NOOOOOO! THERE ARE POTATOES IN MY PASSWORD! ABORT! ABORT!' | mail root
else
  echo "foo. Foo? passwords are clean..." | mail root
fi

# The \< \> are to match a whole word only


Yes! That's what I needed! Thanks, Stefan!

Just as a side question . . . . Some things I've read over the years indicate that a conditional needs to be in brackets, and some indicate that the word "then" should be on the same line as the conditional following a semi-colon. Is there any canonical structure to an if-then-else statement in BASH, or are there four or five ways of styling the statement? (Or this question may be too involved to address here, in which case just ignore it.) Thanks!

--
Kent



Reply to: