Shell Scripting Commands

In shell scripting How to indentify that the previous command was run successfully?

Questions by siddhishah_999

Showing Answers 1 - 8 of 8 Answers

garima2k1

  • May 2nd, 2009
 

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

  Was this answer useful?  Yes

khadsesunil

  • Jun 11th, 2009
 

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  

  Was this answer useful?  Yes

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.

  Was this answer useful?  Yes

Nagunix

  • Jun 6th, 2010
 

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.

  Was this answer useful?  Yes

abdas

  • Jun 26th, 2011
 

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.

  Was this answer useful?  Yes

Give your answer:

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

Answer Question

Click here to Login / Register your free account


 
Send   Reset

 

Related Answered Questions

 

Related Open Questions