[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How Bash echo line start from previous line
From: |
Greg Wooledge |
Subject: |
Re: How Bash echo line start from previous line |
Date: |
Mon, 21 Aug 2023 09:07:53 -0400 |
On Mon, Aug 21, 2023 at 02:26:59PM +0200, alex xmb ratchev wrote:
> ~ $ s=$'\e[1A\e[1G' ; echo abc ; echo "$s"two
> two
> ~ $
You're using two hard-coded terminal sequences. Assuming an xterm-like
terminal, the first appears to be "move cursor up one line" ("cuu=").
The second one appears to be some form of "move cursor to column C"
("hpa=" or "horizontal position absolute").
So, if I'm reading your gibberish correctly, you are moving the cursor
up one line, and then moving the cursor to column 1.
This is not how I interpret the OP's question. The OP's question seems
to be something along the lines of "I run a command that writes some
output followed by a newline. I want to write some text after that
command's output, but on the same line as it, as if the command had not
written a final newline".
In order to do that, you would need to know the number of characters
written to the previous line. You can't just move the cursor to
column 1.
The OP is not giving us a clear indication of the actual goal (classic
X/Y problem here). If the underlying problem actually *is* what I wrote
above, then perhaps the OP could capture the offending command's output
with a command substitution, then spit it back out with printf %s "$capture".
Command substitutions strip all trailing newlines, so that would give
the desired result, so long as there's no issue with waiting for the whole
output before writing any output.
If, however, the offending command takes a long time to execute,
and produces output along the way, and if there's a desire to *see*
this output in progress, instead of all at once upon termination,
then there is no sensible solution to the problem. At that point,
you'd need to look for things that can query the contents of the
terminal, find out where the rightmost non-blank cell is, and move
the cursor to that position.
Good luck finding a tool that can do *that*.
OP, please communicate your goals clearly. Don't make us guess what
you're trying to do. Just tell us.