Remember that grep
is line based. If any line matches, you got a match. (In your first case test.zip
matches (more precisely: you used with -v
therefore you have asked for lines that do not match your pattern, and test.zip
does exactly that, i.e. does not match your pattern. As a result your grep call was successful). Compare
$ grep -vE '^[.]' <<<$'.\na'; echo $?
a
0
with
$ grep -vE '^[.]' <<<$'.\n.'; echo $?
1
Note how the first command outputs the line a
, that is it has found a match, which is why the exit status is 0. Compare that with the second example, where no line was matched.
References
<<<
is a here string:
Here Strings
A variant of here documents, the format is:
[n]<<<word
The word undergoes brace expansion, tilde expansion, parameter and
variable expansion, command substitution, arithmetic expansion, and
quote removal. Pathname expansion and word splitting are not per-
formed. The result is supplied as a single string, with a newline
appended, to the command on its standard input (or file descriptor n if
n is specified).
$ cat <<<'hello world'
hello world
$'1\na'
is used to get a multi line input (\n
is replaced by newline within $'string'
, for more see man bash
).
$ echo $'1\na'
1
a