[–] gcb 16y ago ↗ so un-unix. [–] silentbicycle 16y ago ↗ Well, it has bash in the title, so surprise surprise.If it were about detecting failed commands in Unix shells, all it would need to say is "$?", though. That's hardly worth a blog post.http://www.openbsd.org/cgi-bin/man.cgi?query=sh
[–] silentbicycle 16y ago ↗ Well, it has bash in the title, so surprise surprise.If it were about detecting failed commands in Unix shells, all it would need to say is "$?", though. That's hardly worth a blog post.http://www.openbsd.org/cgi-bin/man.cgi?query=sh
[–] steveitis 16y ago ↗ This article describes any easy way to do this incorrectly.It also has simple spelling errors, such as 'weather' for 'whether'.It is NOT what I've come to expect from HN. Downvotes for everyone involved. Oh. Right. I can't downvote. Damn.
[–] derobert 16y ago ↗ Much better approach (assuming all your terminals use the same colors codes, you could of course use tput if not): RED="\[\033[31;1m\]" NORMAL="\[\033[0m\]" PS1_INSIDE='\u@\h:\w$bad\$ ' PS1="\` retcode=\$? ; if [ 0 -ne \$retcode ]; then bad=\" [\\\\\\\$?=\$retcode]\" echo \"$RED$PS1_INSIDE$NORMAL\" else bad=''; echo \"$PS1_INSIDE\"; fi; \`" unset RED NORMAL PS1_INSIDE Examples: anthony@Tao:~$ true anthony@Tao:~$ false anthony@Tao:~ [$?=1]$ # actually in bold red
4 comments
[ 3.6 ms ] story [ 21.0 ms ] threadIf it were about detecting failed commands in Unix shells, all it would need to say is "$?", though. That's hardly worth a blog post.
http://www.openbsd.org/cgi-bin/man.cgi?query=sh
It also has simple spelling errors, such as 'weather' for 'whether'.
It is NOT what I've come to expect from HN. Downvotes for everyone involved.
Oh. Right. I can't downvote. Damn.