Thank you @GordonDavisson and @choroba in the comments!
The output of kscreen-doctor
is colorized, which means that grep
sees a lot more than what comes across in a copy/pasted terminal dump. Instead of colors, it sees "a bunch of junk" that messes up the match, as | LC_ALL=C cat -vt
on the end shows:
$ kscreen-doctor --outputs | LC_ALL=C cat -vt
^[[01;32mOutput: ^[[0;0m65 eDP-1 ^[[01;32menabled^[[0;0m ^[[01;32mconnected^[[0;0m ^[[01;32mpriority 1^[[0;0m ^[[01;33mPanel^[[01;34m Modes: ^[[0;0m70:^[[01;32m1920x1080@60*^[[0;0m! 71:1920x1080@60 72:1920x1080@48 73:1680x1050@60 74:1400x1050@60 75:1600x900@60 76:1280x1024@60 77:1400x900@60 78:1280x960@60 79:1440x810@60 80:1368x768@60 81:1280x800@60 82:1280x720@60 83:1024x768@60 84:960x720@60 85:928x696@60 86:896x672@60 87:1024x576@60 88:960x600@60 89:960x540@60 90:800x600@60 91:840x525@60 92:864x486@60 93:700x525@60 94:800x450@60 95:640x512@60 96:700x450@60 97:640x480@60 98:720x405@60 99:684x384@60 100:640x360@60 101:512x384@60 102:512x288@60 103:480x270@60 104:400x300@60 105:432x243@60 106:320x240@60 107:360x202@60 108:320x180@60 ^[[01;33mGeometry: ^[[0;0m0,0 1920x1080 ^[[01;33mScale: ^[[0;0m1 ^[[01;33mRotation: ^[[0;0m1 ^[[01;33mOverscan: ^[[0;0m0 ^[[01;33mVrr: ^[[0;0mincapable ^[[01;33mRgbRange: ^[[0;0munknown^[[0;0m
^[[01;32mOutput: ^[[0;0m66 VGA-1 ^[[01;31mdisabled^[[0;0m ^[[01;31mdisconnected^[[0;0m ^[[01;31mpriority 0^[[0;0m ^[[01;33mVGA^[[01;34m Modes: ^[[0;0m^[[01;33mGeometry: ^[[0;0m0,0 0x0 ^[[01;33mScale: ^[[0;0m1 ^[[01;33mRotation: ^[[0;0m1 ^[[01;33mOverscan: ^[[0;0m0 ^[[01;33mVrr: ^[[0;0mincapable ^[[01;33mRgbRange: ^[[0;0munknown^[[0;0m
^[[01;32mOutput: ^[[0;0m67 DP-1 ^[[01;31mdisabled^[[0;0m ^[[01;31mdisconnected^[[0;0m ^[[01;31mpriority 0^[[0;0m ^[[01;33mDisplayPort^[[01;34m Modes: ^[[0;0m^[[01;33mGeometry: ^[[0;0m0,0 0x0 ^[[01;33mScale: ^[[0;0m1 ^[[01;33mRotation: ^[[0;0m1 ^[[01;33mOverscan: ^[[0;0m0 ^[[01;33mVrr: ^[[0;0mincapable ^[[01;33mRgbRange: ^[[0;0munknown^[[0;0m
^[[01;32mOutput: ^[[0;0m68 HDMI-1 ^[[01;31mdisabled^[[0;0m ^[[01;31mdisconnected^[[0;0m ^[[01;31mpriority 0^[[0;0m ^[[01;33mHDMI^[[01;34m Modes: ^[[0;0m^[[01;33mGeometry: ^[[0;0m0,0 0x0 ^[[01;33mScale: ^[[0;0m1 ^[[01;33mRotation: ^[[0;0m1 ^[[01;33mOverscan: ^[[0;0m0 ^[[01;33mVrr: ^[[0;0mincapable ^[[01;33mRgbRange: ^[[0;0munknown^[[0;0m
^[[01;32mOutput: ^[[0;0m156 DVI-I-1-1 ^[[01;31mdisabled^[[0;0m ^[[01;31mdisconnected^[[0;0m ^[[01;31mpriority 0^[[0;0m ^[[01;33mDVI^[[01;34m Modes: ^[[0;0m^[[01;33mGeometry: ^[[0;0m0,0 0x0 ^[[01;33mScale: ^[[0;0m1 ^[[01;33mRotation: ^[[0;0m1 ^[[01;33mOverscan: ^[[0;0m0 ^[[01;33mVrr: ^[[0;0mincapable ^[[01;33mRgbRange: ^[[0;0munknown^[[0;0m
^[[01;32mOutput: ^[[0;0m189 DVI-I-2-2 ^[[01;31mdisabled^[[0;0m ^[[01;31mdisconnected^[[0;0m ^[[01;31mpriority 0^[[0;0m ^[[01;33mDVI^[[01;34m Modes: ^[[0;0m^[[01;33mGeometry: ^[[0;0m0,0 0x0 ^[[01;33mScale: ^[[0;0m1 ^[[01;33mRotation: ^[[0;0m1 ^[[01;33mOverscan: ^[[0;0m0 ^[[01;33mVrr: ^[[0;0mincapable ^[[01;33mRgbRange: ^[[0;0munknown^[[0;0m
^[[01;32mOutput: ^[[0;0m222 DVI-I-3-3 ^[[01;31mdisabled^[[0;0m ^[[01;31mdisconnected^[[0;0m ^[[01;31mpriority 0^[[0;0m ^[[01;33mDVI^[[01;34m Modes: ^[[0;0m^[[01;33mGeometry: ^[[0;0m0,0 0x0 ^[[01;33mScale: ^[[0;0m1 ^[[01;33mRotation: ^[[0;0m1 ^[[01;33mOverscan: ^[[0;0m0 ^[[01;33mVrr: ^[[0;0mincapable ^[[01;33mRgbRange: ^[[0;0munknown^[[0;0m
^[[01;32mOutput: ^[[0;0m255 DVI-I-4-4 ^[[01;31mdisabled^[[0;0m ^[[01;31mdisconnected^[[0;0m ^[[01;31mpriority 0^[[0;0m ^[[01;33mDVI^[[01;34m Modes: ^[[0;0m^[[01;33mGeometry: ^[[0;0m0,0 0x0 ^[[01;33mScale: ^[[0;0m1 ^[[01;33mRotation: ^[[0;0m1 ^[[01;33mOverscan: ^[[0;0m0 ^[[01;33mVrr: ^[[0;0mincapable ^[[01;33mRgbRange: ^[[0;0munknown^[[0;0m
$
That is what grep
actually sees, and so the search string needs to account for it. One way to do that is to forbid a character instead of requiring one:
$ kscreen-doctor --outputs | grep [^s]connected
Output: 65 eDP-1 enabled mconnected priority 1 Panel Modes: 70:1920x1080@60*! 71:1920x1080@60 72:1920x1080@48 73:1680x1050@60 74:1400x1050@60 75:1600x900@60 76:1280x1024@60 77:1400x900@60 78:1280x960@60 79:1440x810@60 80:1368x768@60 81:1280x800@60 82:1280x720@60 83:1024x768@60 84:960x720@60 85:928x696@60 86:896x672@60 87:1024x576@60 88:960x600@60 89:960x540@60 90:800x600@60 91:840x525@60 92:864x486@60 93:700x525@60 94:800x450@60 95:640x512@60 96:700x450@60 97:640x480@60 98:720x405@60 99:684x384@60 100:640x360@60 101:512x384@60 102:512x288@60 103:480x270@60 104:400x300@60 105:432x243@60 106:320x240@60 107:360x202@60 108:320x180@60 Geometry: 0,0 1920x1080 Scale: 1 Rotation: 1 Overscan: 0 Vrr: incapable RgbRange: unknown
$
It shows part of the formatting that is normally hidden (the m
before connected
), but that's okay for me because it's in a script that only cares about the exit code. If you care about stdout, then there's some more work to do.