yes, exactly. Here's a "screenshot" for you:

~$ test 1 == 2
[1] ~$ test 1 == 1
~$

The "[1]" indicates that the "test" command returned the error code 1.

Most commands also print an error code when something goes wrong, but this
little bit of wizardry is very useful for the ones that don't.

Cheers,
JP

On Tue, 16 Nov 2004, William L. Jarrold wrote:

> Cool.
>
> So, lemme see I understand what you are saying. I could
> include the chunk of code below in my .profile and from
> now on (after I relogin or source .profile), any time
> a unix function returns with an error, I'll get to
> see what code is associated with the error (I'm assuming there
> is a whole set of error codes)?
>
> Bill
>
> On Tue, 16 Nov 2004, Jean-Philippe Martin wrote:
>
> > You may already know this technique, but just in case - Instead of `echo
> > $?` I like to set my prompt to show the return code of programs, but only
> > in case of errors. Here's the bash script:
> >
> > # meant to be sourced from your bash environment
> > # this will display a colored error code if the previous function
> > # returned an error, or just the regular prompt otherwise.
> > #
> > # JPM <[EMAIL PROTECTED]>
> >
> > showIfError ()
> > {
> >   AUX=$?;
> >   if [ $AUX -gt 0 ]; then PREFIX="\[\033[1;33m\][${AUX}] "; else
> > PREFIX=""; fi
> >   PS1="${PREFIX}\[\033[1;32m\]\w\[\033[0;0m\]\$ ";
> > }
> >
> > PROMPT_COMMAND=showIfError
> >
> >
> > You can test that with commands like `test 1 == 2` which return an error
> > code.
> >
> > The code above also has colors, but you can remove them if you prefer a
> > vanilla prompt.
> >
> > Cheers,
> > JP
> >
>
_______________________________________________
Siglinux mailing list
[EMAIL PROTECTED]
http://machito.utacm.org/mailman/listinfo/siglinux

Reply via email to