0

I'm using the escape sequence \u001B[6n to find the current terminal cursor location in linux. However, when I run the command echo -e '\u001B[6n', the response is seemingly written as input to the terminal?

I'm trying to use this command from another process and so I need the result written to stdout directly. The below example of echo -e '\u001B[6n' ; read -d R therefore might seem fine in the console but does not work in practice.

  1. Why is the response (at least seemingly) written to the input line of the terminal? Does echo yield this behaviour and if so why?

  2. Is there a way to have the result from the echo printed "as usual" (to stdout), or is there another way (command) to retrieve the cursor location?

echo -e '\u001B[6n'

EDIT

As this question got flagged as a duplicate of this question, I would like to highlight

  1. the explicit requirement of avoiding the command read
  2. The question as to why the output of echo -e (as well as printf) end up on the input line in the terminal
Community
  • 1
  • 1
Felix ZY
  • 674
  • 6
  • 14
  • FYI, `echo -e` is not particularly good form -- bash has to literally violate the letter of the POSIX specification to provide it (unlike most bashisms which are in undefined space), and *doesn't* perform that violation in all modes and configurations (see the `xpg_echo` option's behavior, particularly in `set -o posix` mode). Consider using `printf '%b'` instead, as suggested in the APPLICATION USAGE section of [the POSIX spec for `echo`](http://pubs.opengroup.org/onlinepubs/009695399/utilities/echo.html). – Charles Duffy Nov 21 '16 at 18:52
  • BTW, which terminal, specifically, supports this escape sequence, and in which emulation mode (that is, with which value for the `TERM` variable)? (Might be useful to anyone trying to reproduce the intended behavior). – Charles Duffy Nov 21 '16 at 18:54
  • I'm currently running this on the standard gnome-terminal in Ubuntu 16.04 64bit. – Felix ZY Nov 21 '16 at 18:58
  • $TERM returns xterm-256color – Felix ZY Nov 21 '16 at 19:00
  • Actually it's not a duplicate (of the suggested q/a), since neither it nor any of the comments address OP's confusion regarding `read` and the standard input. – Thomas Dickey Nov 23 '16 at 14:20

0 Answers0