console show strange prompt prefix like this:

;user@centos:~[user@centos ~]$ echo $PS1
[\u@\h \W]\$ 
;user@centos:~[user@centos ~]$ 

this problem just appear in console, ssh remote login no this problem.

system info:

;user@centos:~[user@centos ~]$ cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
;user@centos:~[user@centos ~]$ echo $0
  • Maybe you have characters in your PS1 which are hidden by your echo command. Try echo -E "$PS1" and printf '%s' "$PS1"|od -cx. Does this reveal anything? – user1934428 Mar 26 '18 at 6:25
  • 1
    Also look at your $PROMPT_COMMAND string (if it's set). – Kusalananda Mar 26 '18 at 6:54
  • @user1934428 these 2 method not show anything – fuyun Mar 26 '18 at 8:25
  • @Kusalananda $PROMPT_COMMAND string is printf "\033]0;%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}" what is this mean – fuyun Mar 26 '18 at 8:26
  • 2
    Off the top of my head, I think it attempts to update the terminal window title to identify the user@hostname:directory, but the console does not support the control code for changing the window title (because the console doesn't have one). It ignores the control code, and the text that was supposed to go into the window title gets prefixed to the prompt instead. Some login script is unconditionally setting the $PROMPT_COMMAND; you should change it to be set only if you're not on the console. – telcoM Mar 26 '18 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.