0
if ! grep $1 'dict'; then
firstword=$1
firstletter=${firstword:0:1};
echo $firstletter

else
    echo "hello"
fi

I'm not sure if it's grep that's running, but when the case is that the word Now is in the file dict it prints the word Now to the standard output. If I put in Noww and Noww isn't in it, it will just print out N. What's causing it to print out Now?

1 Answer 1

1

What's causing it to print out "Now"?

grep is printing out Now, because that's what grep does by default: it prints out input lines which match the pattern.

If you don't want grep to do that, use the -q option. Then it will only set the return status, which is what if cares about.

(from man grep on a Linux system):

 -q, --quiet, --silent
      Quiet;  do not write anything to standard output.  Exit
      immediately with zero status if any match is found, even
      if an error was detected...
Sign up to request clarification or add additional context in comments.

2 Comments

Ah thanks, for some reason I did not see that in the options.
If this answer fulfilled your needs. You should appreciate the help using Accepting the Answer rather saying Thanks in Comment. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.