[TAG] Just Bad and Wrong... yet cool
Jimmy O'Regan
jimregan at o2.ie
Fri Oct 14 14:58:10 MSD 2005
Jimmy O'Regan wrote:
> Raj shekhar wrote:
>> in infinite wisdom Jimmy O'Regan spoke thus on 10/14/05 06:09:
>>> Followed by:
>>>
>>> :) fishsticks$ false
>>> :( fishsticks$
>>
>> How did he do that. I want something like that too. If anyone knows,
>> do tell.
>>
>
> ``
> jimregan at jimmy ~
> $ echo $PS1
> \[\033]0;\w\007 \033[32m\]\u@\h \[\033[33m\w\033[0m\] $
>
> jimregan at jimmy ~
> $ smiley () { if [ $? == 0 ]; then echo ':)';else echo ':(';fi; }
>
> jimregan at jimmy ~
> $ PS1="\$(smiley) \h$ "
> :) jimmy$ false
> :( jimmy$ true
> :) jimmy$
> ''
Um... I should probably explain that.
$? holds the exit status of the last process: zero for success, non-zero
for failure; $PS1 is the primary prompt.
It's \$(smiley) because you want bash to evaluate it every time:
$(smiley) would just evaluate it at the time you set the variable, as
would putting the contents of the smiley function into PS1
\h is the shorthand for \$(hostname)
More information about the TAG
mailing list