1748143 Members
3628 Online
108758 Solutions
New Discussion юеВ

What does this do?

 
SOLVED
Go to solution
Greg White
Frequent Advisor

What does this do?

Hi experts:

I found this line in a script and I have no idea what it is supposed to do.

echo "\033[11;21H\c"

Any ideas?

Thanks,
Greg
I know how to do it in pascal.
9 REPLIES 9
Jeff_Traigle
Honored Contributor

Re: What does this do?

Well, the simple way to find out is to run it and see what it does (as a non-root user, of course). Looks like it prints the next text (the command prompt when run interactively) positioned 11 rows down from the current position and column 21.
--
Jeff Traigle
Hein van den Heuvel
Honored Contributor

Re: What does this do?

Looks like a ANSI / VT100 style terminal output addressing to me.

The 033 is octal for ESCAPE (27 decimal) and with the "[" introduces the escape sequence.
The 11;21H is director cursor addressing:
row:colH
The remainder goes to the tube.

fwiw,
Hein.
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: What does this do?

Dumb question deserves dumb answer:

It sends ESC,[11;21H to stdout.

Now to avoid chastisement I will tell you what I think it is (and go find a baseball bat for programmer adjustment):

I think that is a sequence of characters that will position the cursor at coordinates
(11,21) on the screen although it mat well be coordinates (10,20) but I would have to see the terminfo entry for "cup" to know for sure. These ordered pairs normally refer to (y,x) positions although at this point this is speculation.

If it ain't broke, I can fix that.
Jonathan Fife
Honored Contributor

Re: What does this do?

Check out this document for more fun terminal control.

http://www.termsys.demon.co.uk/vtansi.htm

As the previous poster have said, it positions the cursor on the 11th line, 21st column.
Decay is inherent in all compounded things. Strive on with diligence
A. Clay Stephenson
Acclaimed Contributor

Re: What does this do?

By the way (and this is why the baseball is needed) is that hard-coding these sequences is state-of-the-art dumb because if a different terminal is used then in all likelyhood, the escape sequence will garbage the screen. The correct approach is something like this:
tput cup 11 21 (though it actually may be 10 20 that's intended).

Using tput queries the terminfo database using the current TERM setting and looks up the cursor position sequence ("cup") and applies the parameters to instantiate the string.

Do an 'untic | grep "cup"' to find your current cursor positioning string. I suspect you will find a relationship between the "cup" entry and your raw string.


If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: What does this do?

Hi Greg:

I would hope that the programmer(?) would learn to use 'tput' for terminal independence, like:

# clear;echo "`tput cup 11 21 `<-- look here!"

See the manpages for 'tput(1)' and 'terminfo(4)' for more information!

Regards!

...JRF...
Greg White
Frequent Advisor

Re: What does this do?

Thanks everyone. Here is the output of untic | grep "cup".
cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A,

I think I see where some of my characters come from but it is confusing.

Thanks again,
Greg
I know how to do it in pascal.
A. Clay Stephenson
Acclaimed Contributor

Re: What does this do?

If you will do a man 4 terminfo and look under the "Parameterized Strings" section, you should figure out how to decode this cryptic string. For example I know know that the programmer was shooting for 10,20 rather than 11,21 because of the %i in the cup string. What actually happens if you use the tput command (and the underlying curses routines) is that the "cup" string is filled out using your supplied arguments and then sent to stdout. The cup string in instantiated -- meaning to go from the abstract to the concrete -- and isn't that a useful word in the context? Well, I first learned the meaning of that word studying curses and termcap (the predecessor to terminfo) routines.

The really dumb part about all of this is that it is much easier to do "tput 10 20" than it is to actually figure out the sequence and hard-code it. Some programmer actually had to work harder to do something dumber. This is probably a 3 whacks with a baseball bat issue but feel free to add additional whacks if needed.
If it ain't broke, I can fix that.
Greg White
Frequent Advisor

Re: What does this do?

Thanks everyone.

I changed the line to "tput cup 10 20" and it works.

Thanks again,
Greg
I know how to do it in pascal.