Saturday, May 17, 2014

Output of cal on Linux contains underscore and backspace

I just ran across some strange behavior in the output of the cal command on Linux.

I am running a perl script on Linux. The script retrieves the output of the Linux cal command with

`cal $month $year`

where $month and $year are set in the script.

I have been running this script for years and have not had a problem before.

The output of the calendar for

cal 5 2014

contains some control characters. For day 18, the output of the day is _1_8, where is the backspace key (hex 08). As you can guess, this runs havoc with my script that is formatting the calendar.

I had to filter the output of the command, replacing occurrences of _

s/_\x08//g

After filtering the output, the script ran as expected.

I ran a test script on all calendars from 1800 to 3000. Only May 2014 has the error.

No comments:

Post a Comment

Followers