Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

If in .bashrc the following reports the 'history number of the current command' (and the exit code of the last command), how can I configure it to report the 'history number of the previous command'?

PS1='[\u@\h]\!:`echo $?` $ ' 
share|improve this question
Did you try subtracting 1? – Ignacio Vazquez-Abrams Jul 4 '12 at 3:26
I'm not sure if I undertand how the syntax would follow on that. Can you explain? Thanks:-) – user98496 Jul 4 '12 at 3:29
up vote 1 down vote accepted

Subtracting one from the history number can be done like this:

PS1='[\u@\h] $((\! -1)):`echo $?` $ '

So that will show the return code of the history entry listed, which makes the prompt look more consistant I imagine.

share|improve this answer
Thanks! That worked:-) – user98496 Jul 4 '12 at 12:09
@user98496 Please accept this answer by clicking the green checkmark if it worked for you. Thanks! – slhck Jul 17 '12 at 3:07

Your Answer


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.