PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > linux.debian.user > view the exit status from command line
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
linux.debian.user debian-user@lists.debian.org.

view the exit status from command line

Réponse
 
LinkBack Outils de la discussion
Vieux 15/08/2007, 10h30   #1
Kamaraju Kusumanchi
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut view the exit status from command line

Let's say I run a command in bash which is run via konsole. How can I view its exit status.

For example, if I do

$test -x debian/rules

I want to know if the command exited with status zero or non-zero. Can this be done in a simple way?

thank for any suggestions
raju

----------------------------------------------------------------------
Finally - A spam blocker that actually works.
http://www.bluebottle.com/tag/4


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 15/08/2007, 10h40   #2
Glennie Vignarajah
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: view the exit status from command line

Le Wednesday 15 August 2007, Kamaraju Kusumanchi(Kamaraju Kusumanchi
<kamaraju@bluebottle.com>) a écrit:

Hi,

> Let's say I run a command in bash which is run via konsole. How
> can I view its exit status.
>
> For example, if I do
>
> $test -x debian/rules


try:
test -x debian/rules ; echo $?
HTH,

--
Glennie Vignarajah
http://www.glennie.fr
An undefined problem has an infinite number of solutions.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 15/08/2007, 10h40   #3
Glennie Vignarajah
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: view the exit status from command line

Le Wednesday 15 August 2007, Kamaraju Kusumanchi(Kamaraju Kusumanchi
<kamaraju@bluebottle.com>) a écrit:

Hi,

> Let's say I run a command in bash which is run via konsole. How
> can I view its exit status.
>
> For example, if I do
>
> $test -x debian/rules


try:
test -x debian/rules ; echo $?
HTH,

--
Glennie Vignarajah
http://www.glennie.fr
An undefined problem has an infinite number of solutions.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 15/08/2007, 13h20   #4
Joachim Fahnenmüller
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: view the exit status from command line

Hi Kamaraju

On Wed, Aug 15, 2007 at 12:51:06AM -0700, Kamaraju Kusumanchi wrote:
> Let's say I run a command in bash which is run via konsole. How can I view its exit status.
>
> For example, if I do
>
> $test -x debian/rules
>
> 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 $?

man bash:
Special Parameters
(...)
? Expands to the status of the most recently executed foreground
pipeline.

>
> thank for any suggestions
> raju
>


HTH
--
Joachim Fahnenmüller


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 15/08/2007, 13h20   #5
Joachim Fahnenmüller
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: view the exit status from command line

Hi Kamaraju

On Wed, Aug 15, 2007 at 12:51:06AM -0700, Kamaraju Kusumanchi wrote:
> Let's say I run a command in bash which is run via konsole. How can I view its exit status.
>
> For example, if I do
>
> $test -x debian/rules
>
> 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 $?

man bash:
Special Parameters
(...)
? Expands to the status of the most recently executed foreground
pipeline.

>
> thank for any suggestions
> raju
>


HTH
--
Joachim Fahnenmüller


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 15/08/2007, 15h40   #6
Kamaraju S Kusumanchi
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: view the exit status from command line

Joachim Fahnenmüller wrote:

>> For example, if I do
>>
>> $test -x debian/rules
>>
>> 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!

raju
--
Kamaraju S Kusumanchi
http://www.people.cornell.edu/pages/kk288/
http://malayamaarutham.blogspot.com/


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 15/08/2007, 15h40   #7
Kamaraju S Kusumanchi
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: view the exit status from command line

Joachim Fahnenmüller wrote:

>> For example, if I do
>>
>> $test -x debian/rules
>>
>> 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!

raju
--
Kamaraju S Kusumanchi
http://www.people.cornell.edu/pages/kk288/
http://malayamaarutham.blogspot.com/


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 15/08/2007, 16h40   #8
Sven Joachim
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: view the exit status from command line

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. :-)

Cheers,
Sven


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 15/08/2007, 16h40   #9
Sven Joachim
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: view the exit status from command line

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. :-)

Cheers,
Sven


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 15/08/2007, 21h20   #10
Ken Irving
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: view the exit status from command line

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!

--
Ken Irving, fnkci@uaf.edu


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 15/08/2007, 21h50   #11
Håkon Alstadheim
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: view the exit status from command line

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.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 15/08/2007, 22h00   #12
Ken Irving
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 15/08/2007, 22h00   #13
Ken Irving
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 15/08/2007, 22h50   #14
Sven Joachim
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: view the exit status from command line

Håkon Alstadheim <hakon@alstadheim.priv.no> writes:

> 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.


Indeed, thanks for enlightening me. I've had this PROMPT_COMMAND for
a few years, never noticed that it is not necessary.

Cheers,
Sven


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 15/08/2007, 22h50   #15
Sven Joachim
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: view the exit status from command line

Håkon Alstadheim <hakon@alstadheim.priv.no> writes:

> 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.


Indeed, thanks for enlightening me. I've had this PROMPT_COMMAND for
a few years, never noticed that it is not necessary.

Cheers,
Sven


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 16/08/2007, 08h10   #16
Jude DaShiell
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: view the exit status from command line

It only takes one line appended to a shell script:
echo $_ >status.log





--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h26.


Édité par : vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,21587 seconds with 24 queries