[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: view the exit status from command line



On Wed, Aug 15, 2007 at 09:42:16PM +0200, Håkon Alstadheim wrote:
> Ken Irving wrote:
>> On Wed, Aug 15, 2007 at 04:21:17PM +0200, Sven Joachim wrote:
>>   
>>> Kamaraju S Kusumanchi <kamaraju@bluebottle.com> writes:
>>>
>>>     
>>>>>> I want to know if the command exited with status zero or non-zero. Can
>>>>>> this be done in a simple way?
>>>>>>           
>>>>> $test -x debian/rules; echo $?
>>>>>
>>>>>         
>>>> Thanks. Exactly what I am after!
>>>>       
>>> Here's a $0.02 recipe from my ~/.bashrc:
>>>
>>> if [ "$PS1" ]; then
>>>    PROMPT_COMMAND='echo -n "$? "'
>>> fi
>>>
>>> This way, an interactive bash will print the exit status of the last
>>> command before its prompt, so you can _always_ see it.  Very handy,
>>> IMO. :-)
>>>     
>>
>> Thanks for this great idea!
>>
>>   
>
> You don't need a command (at least with the versions of bash I've used the 
> last 10 years), just make sure the variable does not get expanded before it 
> is assigned to PS1. Like so: PS1='$?\$ '. now try executing /bin/true and 
> /bin/false.

Right, I was referring to including the exit value in the prompt.
I usually prefer to have a two-line prompt so I can see my current path,
which sometimes gets unwieldy; e.g.,

    PS1='\u@\h:\w/\n$?\$ '

results in

    ken@hayes:~/proj/source/perl/thinobject/tob-lib/BaseClass/
    0$ 

Ken

-- 
Ken Irving, fnkci@uaf.edu



Reply to: