GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Operating System  >  Shell Scripting
Go To First  |  Previous Question  |  Next Question 
 Shell Scripting  |  Question 46 of 47    Print  
Shell Scripting Commands
In shell scripting How to indentify that the previous command was run successfully?


  
Total Answers and Comments: 6 Last Update: September 18, 2009     Asked by: siddhishah_999 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: dominic_pc1
 
echo $?

if the output of command is 0 than succesfully executed
if the output is non -zero than not successfully executed.

Above answer was rated as good by the following members:
amitkshirsagar, Goriparthi
May 02, 2009 05:48:35   #1  
garima2k1 Member Since: May 2009   Contribution: 1    

RE: Shell Scripting Commands
If a command is executed successfully then the exit status of a command is 0. We can test whether a command is execute successfully or not by writing 2 line

[ command_name ] # command_name is any unix command
echo $?

# $? contains success/failure of the last command that has been executed

 
Is this answer useful? Yes | No
May 06, 2009 11:46:06   #2  
dominic_pc1 Member Since: May 2009   Contribution: 1    

RE: Shell Scripting Commands
echo $?

if the output of command is 0 than succesfully executed
if the output is non -zero than not successfully executed.

 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
May 27, 2009 12:29:54   #3  
bhaileem Member Since: May 2009   Contribution: 2    

RE: Shell Scripting Commands
S? to check whether to check the previous statement was executed successfully.
To display use echo command.

 
Is this answer useful? Yes | No
June 11, 2009 10:11:13   #4  
khadsesunil Member Since: September 2008   Contribution: 1    

RE: Shell Scripting Commands
as per my knowledge if any person executing any command on unix prompt definately either it will the output or syntax error.If you are executing any script and you want to check the whether it completed successfully or not.Then execute the script in debugging mode.
If anybody have a better answer then please forward me on khadsesunil@gmail.com

 
Is this answer useful? Yes | No
June 18, 2009 10:21:34   #5  
sanjayojha02 Member Since: April 2009   Contribution: 3    

RE: Shell Scripting Commands

If you want to check that your script has successfully ran. For this you have to do error handling for each command by displaying echo $?

"?" is a inbuilt variable in Shell Scripting the value for this is assinged by shell after execution of any command to zero(success) or non-zero(failure).

so check this after each command. If somewhere it throws the unexpected values than do error handling there.


 
Is this answer useful? Yes | No
September 18, 2009 08:20:12   #6  
kamalesh_greek Member Since: September 2009   Contribution: 2    

RE: Shell Scripting Commands
Using echo $?
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape