I am trying to log output from an interactive command-line program; units, specifically.

I have tried using tee like this:

units | tee units.log

or script like this:

script -c units units.log

but they both log all the backspaces and tab completions as special characters like this:

You have: 55 horsepower ^G/^H^[[K^M
You want: wat^Gt ^M
    * 41013.493^M
    / 2.438222e-05^M

The manpage for script mentions this issue.


Script places everything in the log file, including linefeeds and backspaces. This is not what the naive user expects.

I am aware of the work-around with viewing the file using cat and more or stripping the escape characters with col as mentioned here:


As well as the perl script here:


But I don't especially want to fix an existing log file: I want to avoid creating new log files garbled with deleted input and control characters.

I thought I had fixed the problem using rlwrap, but it conflicts with the units readline functionality, so that it either fails to capture the output, or with rlwrap -a it captures the output but negates the ability of units to use tab-completion. rlwrap -a -N does not help. This is well-documented in the man page:


Though it is flexible, delivers the goods (readline functionality), and adheres to the Unix "many small tools" paradigm, rlwrap is a kludge. It cannot know anything about command's internal state, which makes context-sensitive completion impossible. Using the readline library from within command is still the best option.

Is there any way to cleanly log interactive input and output that doesn't mess with the existing readline functionality?

Update: I would be happy with something like

units | col -b | tee units.log

but that hangs while waiting for interactive input. Can this be fixed?

  • Are you sure? I initially tried this with tee (GNU coreutils) 8.13 and GNU Units version 1.87 on Ubuntu 12.04, and have since verified it with units 2.02 and the latest version of gnu coreutils from the git repository. – Nathaniel M. Beaver Nov 15 '13 at 22:37
  • How did you determine that there were no control characters in the text file? – Nathaniel M. Beaver Nov 15 '13 at 23:31
  • I take that back, I do indeed have the control chars. Must have done something silly. – terdon Nov 16 '13 at 3:49

GNU Units recently added this feature in version 2.10.

The --log option allows you to save the results of calculations in a file; this can be useful if you need a permanent record of your work.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.