Reputation: 1482
I am going thru with different grep option. and I have following grep command
result=$(echo "ABC DEF" | grep -q " ? ")
I know, -q
option in grep will silent the output.
Does " ? "
have specific meaning in grep
command or it will just match " ? "
as string/characters?
Upvotes: 1
Views: 136
Reputation: 95968
With no flags to indicate the input is a regex, it has no special meaning.
Test:
~$ echo "hello ? world" | grep " ? "
hello ? world
Test with the -q
flag:
~$ echo "hello ? world" | grep -q " ? "; echo $?
0
$?
holds the exit status of the last command. grep
was the last command before echo
, and it returns 0 when it matches.
If you try a non-matching string, you'll get:
~$ echo "hello world" | grep -q " ? "; echo $?
1
Upvotes: 3