flee@gondor.cs.psu.edu (Felix Lee) (06/28/88)
Does ksh let you put the return code in the prompt? Something like PS1='($?) '? Showing only non-zero return codes would be better. Return codes are interesting. Really. IBM's VM/CMS will tell you about non-zero return codes. (The prompt is either 'R;' or 'R(nnn);') Unix hides return codes well. Ever try unconfusing someone about why "true" is "exit 0", but "false" is "exit 1"? Maybe if the shell shouted the return code, more programs would return interesting codes. (lament) Where are the return codes for fsck documented? Why does "strings" return -40? Why does "od" return 10? -- Felix Lee flee@gondor.cs.psu.edu *!psuvax1!gondor!flee
lvc@tut.cis.ohio-state.edu (Lawrence V. Cipriani) (06/28/88)
In article <3671@psuvax1.cs.psu.edu>, flee@gondor.cs.psu.edu (Felix Lee) writes: > Does ksh let you put the return code in the prompt? Something like > PS1='($?) '? Yes, this PS1 displays the exit value of the "previous command". $? will change value on an interrupt however. > Showing only non-zero return codes would be better. Why? Knowing a command completed successfully might be useful if stdout/stderr for the command were redirected. > Return codes are interesting. Really. IBM's VM/CMS will tell you about > non-zero return codes. (The prompt is either 'R;' or 'R(nnn);') Return codes are boring. Really. > Unix hides return codes well. If you need them you can get them, if you don't want to see them you don't have to. I bet you don't have this flexibility in IBM's VM/CMS. My feeling is the shorter my PS1 prompt the better. There was a time when my PS1 included my login id, the machine name I was logged in on, the time of day (you can do this in ksh), and even some graphics sequences. After a few weeks I changed it all back to just the machine name (since I will simultaneously be logged in several systems). >Ever try unconfusing someone about why > "true" is "exit 0", but "false" is "exit 1"? Yeah, and read the man page for true/false to them, it always gets funny looks, and usually some laughs after you explain it to them. ... > Felix Lee flee@gondor.cs.psu.edu *!psuvax1!gondor!flee -- Larry Cipriani, AT&T Network Systems and Ohio State University Domain: lvc@tut.cis.ohio-state.edu Path: ...!cbosgd!osu-cis!tut.cis.ohio-state.edu!lvc (strange but true)
rdp@spike.stars.flab.Fujitsu.JUNET (Richard Palmer) (06/30/88)
In article <3671@psuvax1.cs.psu.edu> flee@gondor.cs.psu.edu (Felix Lee) writes: >Does ksh let you put the return code in the prompt? Something like >PS1='($?) '? Showing only non-zero return codes would be better. PS1="\${?%0} $" seems to do what you want. -- Richard Palmer uunet!spike!rdp 3939 Houma Blvd., #5, Metairie, LA 70006 504-888-5315
dupuy@douglass.columbia.edu (Alexander Dupuy) (07/01/88)
In <3671@psuvax1.cs.psu.edu>, flee@gondor.cs.psu.edu (Felix Lee) writes: > Does ksh let you put the return code in the prompt? Something like > PS1='($?) '? ... > Showing only non-zero return codes would be better. Here's what I do in my .kshrc ($ENV) file: status() { integer status=$? if [ $status -gt 128 -a $status -lt 160 ]; then echo "[Signal `expr $status - 128`]" else echo "[Status $status]" fi } trap 'status 1>&2' ERR # don't let commands fail silently With this, if any command exits with non-zero status, I see what it is. If there's no display, I know the status code was 0. Something similar works for csh or SVR2 sh, but there is no ERR trap, so you have to invoke it manually after every command. SVR2 sh: status() { status=$? if [ $status -gt 128 -a $status -lt 160 ]; then echo "[Signal `expr $status - 128`]" else echo "[Status $status]" fi unset status } csh: alias status 'echo "[Status $status]"' @alex -- inet: dupuy@columbia.edu uucp: ...!rutgers!columbia!dupuy