cal doesn't remove all formatting when stdout is a pipe
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
bsdmainutils (Debian) |
Fix Released
|
Unknown
|
|||
bsdmainutils (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
$ date
Tue Sep 18 13:20:02 PDT 2012
$ cal | hexdump -C
00000000 20 20 20 53 65 70 74 65 6d 62 65 72 20 32 30 31 | September 201|
00000010 32 20 20 20 20 20 0a 53 75 20 4d 6f 20 54 75 20 |2 .Su Mo Tu |
00000020 57 65 20 54 68 20 46 72 20 53 61 20 20 0a 20 20 |We Th Fr Sa . |
00000030 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | |
00000040 20 31 20 20 0a 20 32 20 20 33 20 20 34 20 20 35 | 1 . 2 3 4 5|
00000050 20 20 36 20 20 37 20 20 38 20 20 0a 20 39 20 31 | 6 7 8 . 9 1|
00000060 30 20 31 31 20 31 32 20 31 33 20 31 34 20 31 35 |0 11 12 13 14 15|
00000070 20 20 0a 31 36 20 31 37 20 5f 08 31 5f 08 38 20 | .16 17 _.1_.8 |
00000080 31 39 20 32 30 20 32 31 20 32 32 20 20 0a 32 33 |19 20 21 22 .23|
00000090 20 32 34 20 32 35 20 32 36 20 32 37 20 32 38 20 | 24 25 26 27 28 |
000000a0 32 39 20 20 0a 33 30 20 20 20 20 20 20 20 20 20 |29 .30 |
000000b0 20 20 20 20 20 20 20 20 20 20 20 0a | .|
000000bc
Note the extra characters around the 1 and the 8 of 18. Compare with:
$ cal -h | hexdump -C
00000000 20 20 20 53 65 70 74 65 6d 62 65 72 20 32 30 31 | September 201|
00000010 32 20 20 20 20 20 0a 53 75 20 4d 6f 20 54 75 20 |2 .Su Mo Tu |
00000020 57 65 20 54 68 20 46 72 20 53 61 20 20 0a 20 20 |We Th Fr Sa . |
00000030 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | |
00000040 20 31 20 20 0a 20 32 20 20 33 20 20 34 20 20 35 | 1 . 2 3 4 5|
00000050 20 20 36 20 20 37 20 20 38 20 20 0a 20 39 20 31 | 6 7 8 . 9 1|
00000060 30 20 31 31 20 31 32 20 31 33 20 31 34 20 31 35 |0 11 12 13 14 15|
00000070 20 20 0a 31 36 20 31 37 20 31 38 20 31 39 20 32 | .16 17 18 19 2|
00000080 30 20 32 31 20 32 32 20 20 0a 32 33 20 32 34 20 |0 21 22 .23 24 |
00000090 32 35 20 32 36 20 32 37 20 32 38 20 32 39 20 20 |25 26 27 28 29 |
000000a0 0a 33 30 20 20 20 20 20 20 20 20 20 20 20 20 20 |.30 |
000000b0 20 20 20 20 20 20 20 0a | .|
000000b8
Changed in bsdmainutils (Debian): | |
status: | Unknown → New |
tags: | added: precise trusty |
Changed in bsdmainutils (Debian): | |
status: | New → Fix Released |
From looking at the source, this is possibly by design, but I'd argue that it's flawed logic to behave this way:
/*
* If it is a real terminal, use the data from the termcap database.
*/
if (term_so != NULL && term_se != NULL) {
/* separator. */
dst[0] = ' ';
dst++;
/* highlight on. */
memcpy(dst, term_so, strlen(term_so));
dst += strlen(term_so);
/* the actual text. (minus leading space) */
len--;
src++;
memcpy(dst, src, len);
dst += len;
/* highlight off. */
memcpy(dst, term_se, strlen(term_se));
*extralen = strlen(term_so) + strlen(term_se);
return;
}
/*
* Otherwise, print a _, backspace and the letter.
*/
*extralen = 0;
/* skip leading space. */
src++;
len--;
/* separator. */
dst[0] = ' ';
dst++;
while (len > 0) {
/* _ and backspace. */
memcpy(dst, "_\010", 2);
dst += 2;
*extralen += 2;
/* the character. */
*dst++ = *src++;
len--;
}
return;