Bug 10411 - grep -v -q not returning expected results when used with blkid
Summary: grep -v -q not returning expected results when used with blkid
Status: NEW
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.27.x
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-10-15 01:27 UTC by Clayton Craft
Modified: 2017-10-15 01:27 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Clayton Craft 2017-10-15 01:27:46 UTC
When trying to grep text from the output of blkid, I noticed that if I use -v along with -q, that grep returns 0 regardless of whether or not there was a match.


For reference, the output of blkid, and grepping blkid with -v:
# blkid
/dev/mmcblk1p3: UUID="5463935a-1361-4043-8a44-75498986c3e8" TYPE="swap"
/dev/mmcblk1p2: UUID="a15f4575-5886-4da6-9e13-caa7e6300f2c" TYPE="ext3"
/dev/mmcblk1p1: LABEL="Nokia N900" UUID="4BB1-EC06" TYPE="vfat"
/dev/mmcblk0p2: LABEL="pmOS_root" UUID="e54fb2af-97c3-4a47-af17-5ab6f0f4dba7" TYPE="ext4"
/dev/mmcblk0p1: LABEL="pmOS_boot" UUID="5c24c382-1921-455f-b63b-dd053e55d0cb" TYPE="ext2"
# blkid |grep -v pmOS_root
/dev/mmcblk1p3: UUID="5463935a-1361-4043-8a44-75498986c3e8" TYPE="swap"
/dev/mmcblk1p2: UUID="a15f4575-5886-4da6-9e13-caa7e6300f2c" TYPE="ext3"
/dev/mmcblk1p1: LABEL="Nokia N900" UUID="4BB1-EC06" TYPE="vfat"
/dev/mmcblk0p1: LABEL="pmOS_boot" UUID="5c24c382-1921-455f-b63b-dd053e55d0cb" TYPE="ext2"


The output of these looks OK:
# blkid |grep -q  nope; echo $?
1

# blkid |grep -q -v nope; echo $?
0

This is NOT expected. The second command should have output 1:
# blkid |grep -q pmOS_root; echo $?
0

# blkid |grep -q -v pmOS_root; echo $?
0


The same test but replacing blkid with echo looks OK:

localhost:/home/user# echo pmOS_root |grep -q pmOS_root; echo $?
0

localhost:/home/user# echo pmOS_root |grep -q -v pmOS_root; echo $?
1