script and ESC sequence characters 

Symptom 

The script will record some weird ESC sequence characters around the bash prompt:

tong@sunny:~$
ESC[?1lESC>ESC[?1hESC=^M
tong@sunny:~$ phd
ESC[?1lESC>ESC[?1hESC=^M
$
ESC[?1lESC>ESC[?1hESC=^M
$ psh
ESC[?1lESC>ESC[?1hESC=^M
tong@sunny:~$
ESC[?1lESC>ESC[?1hESC=^M

Reason 

bash is trying to be smart

Solution 

set the TERM to invalid entry:

TERM=vt444

to test, use clear:

$ clear
'vt444': unknown terminal type.
[Tip]

!!

OK!