Bash – What does it mean when characters appear on the prompt after an operation

bashescape-characters

Compare the following two commands:

mysqldump database_name --hex-blob -uuser_name -p | tee database_name_tee.sql
mysqldump database_name --hex-blob -uuser_name -p > database_name_out.sql

If I run the first, on completion I see the following on my terminal:

$ 62;c62;c62;c62;c

Where does this come from? Does it suggest that something has gone wrong somewhere in the process? Are these control characters which are being output for some reason?

U+0C62 is Telugu Vowel Sign Vocalic L, which I’m pretty sure is not part of my data, so I don’t think this is Unicode. Anyway, the sequence seems to be not c62 but 62;c. This could be a control character of some kind. And whatever is causing it is included in the output file. If I later cat either database_name_tee.sql or database_name_out.sql, I again see this sequence once the cat is complete.

tail database.sql -n200 does not produce this output; -n300 produces just $ 62;c62;c; and -n400 produces $ 62;c62;c62;c62;c. So whatever is causing this is distributed throughout the file.

Mucking around with head and tail, I found one of the culprits: a single line which, when saved to a separate file and printed with cat, produces $ 62;c62;c. My problem is that this single line is 1043108 bytes.

(The generated SQL file is perfectly fine, and runs without errors. I don’t think that this has anything to do with MySQL per se.)

I’m running the initial mysqldump on a CentOS server, and am seeing the same effects from cat on both the server itself and my Ubuntu desktop, so this seems to be a general Bash thing.

od -c problem_line produces 65174 lines of output, so I cut it down to a smaller section which demonstrates the same output (also available as a plain hexdump).

Best Answer

There are no escape characters in the octal dump (those would be 033).

There are a few 8-bit control codes (generally not implemented by most terminals other than xterm). The octal 232 is hex 0x9a, and (referring to XTerm Control Sequences):

ESC Z
     Return Terminal ID (DECID is 0x9a).  Obsolete form of CSI c  (DA).

...
CSI Ps c  Send Device Attributes (Primary DA).
            Ps = 0  or omitted -> request attributes from terminal.  The
          response depends on the decTerminalID resource setting.
...
            -> CSI ? 6 c  ("VT102")

The characters come from a response by the terminal to the DECID control character. The details of the response depend on the terminal emulator (which was not mentioned in the question).

Related Question