Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash exit status always 0

I'm experiencing this weird issue where my exit status always return 0 even when it didn't execute successfully.

I want to output the exit status on my prompt with the following code:

function status() {
    echo $?
}

export PS1="\$(status)>"

When I run this, I get the following output

 0❯ pwd
/Users/tringuyen
 0❯ ad
bash: ad: command not found
 0❯ echo $?
127

clearly the second last command ad didn't return a 0 status code. However that's what I got from the prompt.

Does anyone know what might be going on here?

EDIT 6/20 11:57AM: The issue seems to be that $? is always 0 no matter what, except there was an error within the .bashrc file itself, which will cause it to return a value different from 0.

like image 692
Tri Nguyen Avatar asked Jun 20 '13 14:06

Tri Nguyen


1 Answers

Does the following work for you with your bash version?

export PS1="\$?>"
like image 53
Moreaki Avatar answered Oct 16 '22 01:10

Moreaki