简体   繁体   中英

Grep match exact string

file.txt
example=0x12; non-match 

grep -w "example=0x0" file.txt

I am trying to match exact string using grep and it looks like echo $? always returns 1.

In this case, the output should have been 0. I have tried -F too.

You need the -q option if you're just checking the exit status. See below for examples

$ grep -qw "A" <<< "AAA"; echo $?
1
$ grep -qw "A" <<< "A"; echo $?
0

first word match fails, exit 1. Second one succeeds, exit 0.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM