export PS1='[\u@\h \w] $(echo $?) \$ 'the trick is the
$(echo $?)I know this forks a new echo process every time you get a shell prompt. But the idea is that you enable this when you are doing important selected stuff. Possibly on a live system where you are not allowed to make any errors.