Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This is somewhat of a cosmetic (and trivial) question, but I suppose it may be useful to others than myself. I've been playing around with the $PS1 variable in my ~/.bashrc, and I was wondering if there was any way to have the first prompt be slightly different than every other prompt. More specifically, so far I have:

PS1='\n\[\e[0;37m\][\[\e[0;35m\]\t\[\e[0;37m\]] \[\e[0;36m\]\u@\h \[\e[0;37m\][\[\e[1;34m\]\W\[\e[0;37m\]] \[\e[0;36m\]\$ \[\e[0m\]'

but I don't want the newline at the beginning to display on the first prompt (and I could extend this to have the first prompt include more info, etc.). I'm using gnome-terminal, if that makes a difference.

Is this at all possible? And if so, how?

share|improve this question
    
I answered a similar question with a too-clever variation on garyjohn's answer. –  chepner Feb 27 '13 at 2:44
    
This would work, but I still want my PROMPT_COMMAND to work for other parts of $PS1. –  user1628477 Feb 28 '13 at 18:52
add comment

2 Answers 2

up vote 1 down vote accepted

One way to do this would be to use bash's PROMPT_COMMAND. For example, you could put the following in your ~/.bashrc (or execute it at the command line while you experiment).

set_ps()
{
    if [ -z "$PSFLAG" ]
    then
        # Set first prompt
        PS1='first prompt: '
        PSFLAG=1
    else
        # Set other prompt
        PS1='other prompt: '
    fi
}
PROMPT_COMMAND=set_ps
share|improve this answer
    
This is what I ended up doing, but instead I just inserted a variable into my $PS1 that gets set for the second prompt and then persists. Thanks! –  user1628477 Feb 28 '13 at 18:51
add comment

If you want some characters to be output before the first prompt and never again, why don’t you just have .bashrc output them?

share|improve this answer
    
The OP wanted fewer characters in the first prompt, i.e., no newline at the beginning. –  garyjohn Feb 27 '13 at 9:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.