Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commandline overwrites itself when the commands get too long

I'm using PuTTY to log into a Debian server. I have this odd problem that when a command I'm typing gets too long, it doesn't wraparound and start a new line. Instead, it starts at the beginning of the same line and starts to overwrite the prompt and then the beginning of the command.

The command will run just fine, but it is really annoying, I'm assuming there is some setting that would fix this for me?

like image 432
Janak Avatar asked Jan 08 '10 01:01

Janak


People also ask

How do I stop an ongoing command?

Hold the Ctrl button and press the C key at the same time. It sends the SIGKILL signal to the running program to force quit the command.

Which character is used to continue a long command on another line?

Continuing a Long Command on Another Line To make the commands easier to understand, use the shell escape character, which is a backslash, to continue a command on the next line.

What happens when & is added to the end of a command?

The & makes the command run in the background. From man bash : If a command is terminated by the control operator &, the shell executes the command in the background in a subshell.

What is the command to repeat the command you just executed?

This is the most dependable shortcut in Linux to execute the last run command in the terminal. Just press the Ctrl and P keys together to fill the prompt with the last executed command and you are ready to go.


1 Answers

I've just solved this myself.

It was just some color escapes in the PS1 command prompt:

LTGREEN="\033[40;1;32m" LTBLUE="\033[40;1;34m" CLEAR="\033[0m" LIGHT_GRAY="\033[40;1;33m" export PS1="$LTGREEN\u$LTBLUE@\h:$LIGHT_GRAY\w$CLEAR ❯ " 

The issue is that the color literals are not enclosed in brackets. Placing escaped brackets around them fixes the issue entirely:

LTGREEN="\[\033[40;1;32m\]" LTBLUE="\[\033[40;1;34m\]" CLEAR="\[\033[0m\]" LIGHT_GRAY="\[\033[40;1;33m\]" export PS1="$LTGREEN\u$LTBLUE@\h:$LIGHT_GRAY\w$CLEAR ❯ " 

Hope this helps.

like image 199
trisweb Avatar answered Oct 04 '22 04:10

trisweb