I am writing a script. What is the difference between the following two lines?
grep . || echo something
grep "^\." || echo something
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
Grep uses regular expressions; there, a single full stop
. matches any single character. To match a literal full stop/period, you need to escape it with a backwards-slash like so:
^ means 'the beginning of the line'.
grep . will match anything that contains a single character (so I suppose it wouldn't match empty lines). On the other hand,
grep "^\." matches any line that starts with a literal
|| means 'or';
grep "^\." || echo something will echo
something if the grep doesn't turn up any lines (so it evaluates to false).
&& is used for 'and' in bash.