In "read", why does the cursor does not move to the next input line when there is 1 character more than there are columns?
0
votes
0
answers
82
views
I have noticed that when providing input to
read
, both Bash's and Dash's, the cursor does not move to the next line if the current line contains 1 character more than there are columns. In MATE Terminal, GNOME Terminal and LXTerminal, the cursor disappears. In xterm and the virtual console the cursor stays in the last column.
If the current line contains 2 character more than there are columns, then in all the aforementioned terminals and the console, the cursor appears on the next input line, in the second column, after the excessive character.
This behavior can be seen in Bash with
read -p "$( x="$( tput 'cols' )" ; for (( y = 0 ; y < x ; ++y )) ; do echo -n 'x' ; done )"
I don't know if the command works in Dash. This command prints the prompt in read
long enough to fill the first line for input with the character "x" until the last column, included (read
waits for further input, so you need to control-d
to return to the shell). Notice that the cursor has disappeared from the terminal (or console).
On the other hand, we see that making the prompt in read
1 character longer causes the cursor to appear on the next line. It can be seen with just changing the 0
in the previous command to -1
, like
read -p "$( x="$( tput 'cols' )" ; for (( y = -1 ; y < x ; ++y )) ; do echo -n 'x' ; done )"
Now we print 1 character more that there are columns, the line wraps, and the cursor is shown.
The behavior that I would expect is that the cursor moves to the next line if the current line contains 1 character more than there are columns (i.e. the cursor never disappears or stays in the last column).
**So, why does the cursor not move? Is it expected behavior? What program or library causes it?**
Asked by decision-making-mike
(179 rep)
Jul 20, 2025, 05:55 PM