Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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. – apottere Feb 28 '13 at 18:52
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).

    if [ -z "$PSFLAG" ]
        # Set first prompt
        PS1='first prompt: '
        # Set other prompt
        PS1='other prompt: '
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! – apottere Feb 28 '13 at 18:51

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .