I found an odd shell bug & I'm not entirely sure who's at fault.
-
I found an odd shell bug & I'm not entirely sure who's at fault. Some interaction between screen, ANSI colors & grep seems to make a char disappear.
Reproducer: run this in screen on a terminal with 80 chars width:
echo -e 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx12345'|grep 234
The "4" disappears mysteriously... Seems to be caused by escape code '[K' from grep. I'd appreciate explanations+whether I should report a bug to screen, grep or elsewhere.
-
I found an odd shell bug & I'm not entirely sure who's at fault. Some interaction between screen, ANSI colors & grep seems to make a char disappear.
Reproducer: run this in screen on a terminal with 80 chars width:
echo -e 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx12345'|grep 234
The "4" disappears mysteriously... Seems to be caused by escape code '[K' from grep. I'd appreciate explanations+whether I should report a bug to screen, grep or elsewhere.
Possibly related, but slightly different issue: if I do this in xterm, but not in screen, the 4 also disappears, but it's not replaced by empty space, but by the 5 (which should end up on the next line)

-
Possibly related, but slightly different issue: if I do this in xterm, but not in screen, the 4 also disappears, but it's not replaced by empty space, but by the 5 (which should end up on the next line)

@hanno what if you pipe to grep 4 the output? is the 4 in the pipe or already eaten by grep?
-
@hanno what if you pipe to grep 4 the output? is the 4 in the pipe or already eaten by grep?
@uint8_t same result with only grepping 4. 4 is in the output. Minimal ANSI escape code PoC without grep looks like this:
echo -e 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1234\033[K5' -
Possibly related, but slightly different issue: if I do this in xterm, but not in screen, the 4 also disappears, but it's not replaced by empty space, but by the 5 (which should end up on the next line)

@hanno If I do this in tmux in xterm, the 4 "reappears".
-
I found an odd shell bug & I'm not entirely sure who's at fault. Some interaction between screen, ANSI colors & grep seems to make a char disappear.
Reproducer: run this in screen on a terminal with 80 chars width:
echo -e 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx12345'|grep 234
The "4" disappears mysteriously... Seems to be caused by escape code '[K' from grep. I'd appreciate explanations+whether I should report a bug to screen, grep or elsewhere.
-
I found an odd shell bug & I'm not entirely sure who's at fault. Some interaction between screen, ANSI colors & grep seems to make a char disappear.
Reproducer: run this in screen on a terminal with 80 chars width:
echo -e 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx12345'|grep 234
The "4" disappears mysteriously... Seems to be caused by escape code '[K' from grep. I'd appreciate explanations+whether I should report a bug to screen, grep or elsewhere.
@hanno Here are a few other examples of disappearing text, the resulting effect depends on the terminal emulator you use. Here on xfce4-terminal (and bash):
$ echo -e "blabla\033\0135blibli\n\n\n" | hexdump -C
00000000 62 6c 61 62 6c 61 1b 5d 62 6c 69 62 6c 69 0a 0a |blabla.]blibli..|
00000010 0a 0a |..|
00000012
$ echo -e "blabla\033\0135blibli\n\n\n"
blabla$ echo -e "blabla\033\0135blibli\n\n\n" | grep bli
blabla$
$
$ echo -e "blabla\n\033\0135blibli\n\n\n" | hexdump -C
00000000 62 6c 61 62 6c 61 0a 1b 5d 62 6c 69 62 6c 69 0a |blabla..]blibli.|
00000010 0a 0a 0a |...|
00000013
$ echo -e "blabla\n\033\0135blibli\n\n\n"
blabla
$ echo -e "blabla\n\033\0135blibli\n\n\n" | grep bli
$
$ echo -e "blabla\033\0135\nblibli\n\n\n" | hexdump -C
00000000 62 6c 61 62 6c 61 1b 5d 0a 62 6c 69 62 6c 69 0a |blabla.].blibli.|
00000010 0a 0a 0a |...|
00000013
$ echo -e "blabla\033\0135\nblibli\n\n\n"
blabla$ echo -e "blabla\033\0135\nblibli\n\n\n" | grep bli
blibli
$
$ echo -e "blabla\033\n\0135blibli\n\n\n" | hexdump -C
00000000 62 6c 61 62 6c 61 1b 0a 5d 62 6c 69 62 6c 69 0a |blabla..]blibli.|
00000010 0a 0a 0a |...|
00000013
$ echo -e "blabla\033\n\0135blibli\n\n\n"
blabla
$ echo -e "blabla\033\n\0135blibli\n\n\n" | grep bli
]blibli
$That's the trick I used for https://github.com/fuxx/GPG-ANSI-Art-Injector/blob/main/designs/fake_key_summary.py and https://codeberg.org/wllm-rbnt/hacklu-2025-CLI-ambush/
-
R relay@relay.infosec.exchange shared this topic