Ask Your Question
0

Prompt before command output in terminal

asked 2017-12-15 12:51:18 -0600

edwardc01 gravatar image

On Fedora 26 when using the terminal window, why does the shell return the prompt (or only part of the prompt) before it outputs the result of the previously input command? I'm running gnome XTerm. This has only started since I upgraded to Fedora 26.

image description

My prompt is defined as two lines with the first line containing my login name@the current directory followed by line 2 which is a $ if I'm a regular user or SU: # if I have become root.

What happens now is that as soon as I enter a command the shell returns the 2nd line of my prompt followed by the output of the command and then a full prompt (both lines).

I have made no changes to my .bashrc or my .bash_profile.

Any help in trying to figure out what's going on would be appreciated. It's annoying especially when the system takes a while to generate output because if you don't look closely you think you have a prompt but you really don't and the system just stacks the commands and you get tons of output that may fill up the terminal buffers making it impossible to scroll back up to find the first command output.

Thanks

edit retag flag offensive close merge delete

Comments

1

Could you please add the contents of your prompt definition?

ssieb gravatar imagessieb ( 2017-12-15 18:57:20 -0600 )edit

I figured it out! My prompt was defined incorrectly, but it had worked for a really long time but I guess bash doesn't now like explicit newlines in variables. See my answer for details.

I quickly formatted your answer below to show you how it can look like. Please revert if you don't like it.

edwardc01 gravatar imageedwardc01 ( 2017-12-19 12:33:23 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2017-12-19 12:56:10 -0600

edwardc01 gravatar image

updated 2017-12-19 14:08:52 -0600

florian gravatar image

Hard to see the difference in the formating that shows in the answer let me try again:

# User specific aliases and functions
uid=`id|sed 's/uid=\([0-9]*\)\(.*$\)/\1/'`
if [ {$uid} = "0" ]
then
    P="SU: # "
else
    P="$ "
fi

# 
case "${TERM}" in
xterm*|rxvt*)
    PS1="[\u@\h: \w\a ]
${P}"
    ;;
*)
    ;;
esac

This doesn't work, here is what works:

    # User specific aliases and functions
uid=`id|sed 's/uid=\([0-9]*\)\(.*$\)/\1/'`
if [ {$uid} = "0" ]
then
    P="SU: # "
else
    P="$ "
fi

# 
case "${TERM}" in
xterm*|rxvt*)
    PS1="[\u@\h: \w\a ]\n${P}"
    ;;
*)
    ;;
esac

Now you can see the subtle difference!

edit flag offensive delete link more

Comments

\n for line break in PS1

florian gravatar imageflorian ( 2017-12-19 14:10:43 -0600 )edit
0

answered 2017-12-19 12:38:16 -0600

edwardc01 gravatar image

My prompt contained an explicit newline within the variable definition and apparently bash no longer will accept that. My prompt definition in .bashrc was as follows:

User specific aliases and functions

uid=id|sed 's/uid=\([0-9]*\)\(.*$\)/\1/' if [ {$uid} = "0" ] then P="SU: # " else P="$ " fi

case "${TERM}" in xterm|rxvt) PS1="[\u@\h: \w\a ] ${P}" ;; *) ;; esac

This worked probably sinced I started using Linux (about 1997) but now it has to be defined like this:

# User specific aliases and functions uid=id|sed 's/uid=\([0-9]*\)\(.*$\)/\1/' if [ {$uid} = "0" ] then P="SU: # " else P="$ " fi

case "${TERM}" in xterm|rxvt) PS1="[\u@\h: \w\a ]\n${P}" ;; *) ;; esac

I should have spent more time troubleshooting before posting but I was pressed for time and let it fly. Sorry!!

edit flag offensive delete link more

Comments

Well guess I don't understand how to keep the formatting when I post.

edwardc01 gravatar imageedwardc01 ( 2017-12-19 12:59:55 -0600 )edit

mark text then hit the 101010 symbol or press Ctrl+K

florian gravatar imageflorian ( 2017-12-19 14:06:26 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-12-15 12:51:18 -0600

Seen: 226 times

Last updated: Dec 19 '17