Valor de retorno en el prompt

Published on 10.05.2006 by Toni

Este código sirve para indicar si el último comando ha tenido éxito o no, de manera que siempre esté visible en el propio prompt, es ideal para depurar código entre otras cosas.

Versión rápida (aunque no muy legible :P ): $ export PS1='$( [ "$?" -eq 0 ] && M=\) || M=\(; echo -n :$M ) '$PS1.

Incluyendo este fragmento en ~/.bashrc siempre estará activo:

# Indicacion de si el ultimo comando ha tenido exito
# inspirada por http://mendel.livejournal.com/128965.html
#export PS1='`test "$?" -eq 0 && echo -n ":)" || echo -n ":(" ` '$PS1
# Version con funcion sacada de http://linuxgazette.net/122/lg_tips.html
#Alternativamente: "More-or-less undocumented Bash-ism - a C-style trinary operator":
#smiley () { echo -e ":\\$(($??50:51))"; }
_smiley() {
if [ $? -eq 0 ]; then echo ':)'
else echo ':('
fi
}
#...
export PS1="\$(_smiley) "$PS1

There are no comments about this page

Leave your comment

XHTML: You can use tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Your comment will require approval before publishing.

Posts RSS Comments RSS


Bad Behavior has blocked 64 access attempts in the last 7 days.