How do I capture the exit value of the previous command in my bash prompt? I want to do this because I also want to include the current git branch in my path as well, and that changes $?
I have tried quite a few variations on the following prompt (e.g. `, ` and $() around the assignment to RETVAL), but RETVAL is empty in all of them:
PS1="\$(RETVAL=$(echo \$))\$(cd 124123)retval: $RETVAL"
The cd command inside is just a placeholder for the call to the git current branch function, and I am echoing RETVAL afterwards (this is always an empty string to test if it gets assigned.
Other questions that are similar/relevant:
- Creating a Bash command prompt with a red $ after failure of previous command -
- Bash prompt with last exit code
I have also tried setting RETVAL in the prompt command using examples like on these pages, but nothing is displayed in the prompt