In file.txt, I've got the following lines:
word1 blahbla
word2 blahbla
..........
Grep works as expected.
grep "word1.*word2" file.txt
gives me output, which I expect, because word1
occurs before word2
.
grep "word2.*word1" file.txt
gives no output, which I expect, because word 2 occurs after word1 and not before it.
The conditional statement does not work as expected.
[ -n '$(grep "word1.*word2" file.txt' ] && echo "output" || echo "no output"
gives me expected result, echoing "output", but ...
[ -n '$(grep "word2.*word1" file.txt' ] && echo "output" || echo "no output"
gives me UNEXPECTED result, echoing "output" when I'm expecting "no output".
What's wrong?