GeekInterview.com
Series: Subject: Topic:
Question: 10 of 55

Shell Scripting Commands

In shell scripting How to indentify that the previous command was run successfully?
Asked by: siddhishah_999 | Member Since Apr-2009 | Asked on: Apr 28th, 2009

View all questions by siddhishah_999

Showing Answers 1 - 8 of 8 Answers
garima2k1

Answered On : May 2nd, 2009

View all answers by garima2k1

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

  
Login to rate this answer.
dominic_pc1

Answered On : May 6th, 2009

View all answers by dominic_pc1

echo $?

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

Yes  3 Users have rated as useful.
  
Login to rate this answer.
bhaileem

Answered On : May 27th, 2009

View all answers by bhaileem

S? to check whether to check the previous statement was executed successfully.
To display use echo command.

  
Login to rate this answer.
khadsesunil

Answered On : Jun 11th, 2009

View all answers by khadsesunil

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  

  
Login to rate this answer.

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.

  
Login to rate this answer.
kamalesh_greek

Answered On : Sep 18th, 2009

View all answers by kamalesh_greek

Using echo $?

  
Login to rate this answer.
Nagunix

Answered On : Jun 6th, 2010

View all answers by Nagunix

Use command

echo $?

at prompt.

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

  
Login to rate this answer.
abdas

Answered On : Jun 26th, 2011

View all answers by abdas

in 2 ways it can be done:
1st way
$ echo $?  

2nd way:

$ pwd 2> error| cat error|wc -l
       0
$ cat h 2> error| cat error|wc -l
       1

pwd or cat or any command if outpt is 0 then successful else failed.

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.