It is the output of the clear
command …
You ran clear
. clear
produced these control sequences. (They are merely in a different order on my machine.)
% clear | cat -v ; echo
^[[2J^[[H^[[3J
%
On an ECMA-48 terminal or terminal emulator these control sequences erase the display and position the cursor.
% clear | console-decode-ecma48
ED 2
CUP 0
ED 3
%
But the watch
command interprets the standard outputs of the processes that it runs, and does not understand any ECMA-48 control sequences apart from one. It only understands some of the TTY-37 control characters from 1968 and (if the -c
flag is used) the SGR control sequence from ECMA-48.
Everything else it passes to ncurses, which prints control characters in caret notation. But because of a bug in watch
, the second character of a caret notation string is then immediately overwritten, and what should have been ^[[
comes out as ^[
in watch
's output.
… and only the clear
command.
The shell script is not quoted at all:
watch -n 10 clear > /dev/pts/0 ; netstat -tupn 2>/dev/null | grep -v 3306 > /dev/pts/0
So this is two pipelines, sequentially:
watch -n 10 clear > /dev/pts/0
netstat -tupn 2>/dev/null | grep -v 3306 > /dev/pts/0
The redirection happens before the commands are run, and in two cases is redirecting standard output to the pseudo-terminal that it was open to anyway. They are effectively no-ops:
watch -n 10 clear
netstat -tupn 2>/dev/null | grep -v 3306
Your machine is doing exactly what you told it to do.
So you are watching the output of just the clear
command, repeatedly, whose output isn't being processed as control sequences but simply printed in broken caret notation.
Exit watch
to run your netstat
command once. ☺
clear
command - not very interesting...clear
every 10 seconds until you hit^C
. After you're done with watching clear, you want to runnetstat
once. And all of this is output to a specific pseudo-terminal.watch
is capturing input, it grabs the escape sequence and displays it. It also sends its ownclear screen
escape sequence to the output terminal independently of the command given.clear > /dev/pts/0
should not give you that "funny screen" on any Linux system, although the results may not be want you expect if your terminal is not/dev/pts/0
.watch clear > /dev/pts/0
is an entirely different command and you should not expect the output to be the same.