Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Re-execution of a script, but not from the beginning

Status
Not open for further replies.

Yanndewael

Programmer
Mar 14, 2003
12
GB
Hello,

I want to write a script with several command, example:

#1
Command 1
#2
Command 2
#3
Command 3
...

I will test the return code of these command and exit the script in case of error. After having investigate the error causes, I want to be able to re-execute the script from the failed command.
Example: if command 3 failed, I'd like to execute "Script 3" and it will not execute command 1 and 2 anymore...

How can I manage? I think to test the parameter before each command: if this parameter is < the command number -> skip.
But this implies to test the parameter before each command and we will loose in clarity.
Any other idea?

Thank you in advance,

Yann
 
When I need to do this, I typically do all the work inside a &quot;case&quot; structure:

[tt]
case &quot;${1}&quot; in
&quot;sub-cmd-a&quot;)
# do the stuff associated with this step
;;
&quot;sub-cmd-b&quot;)
# do the stuff associated with this step
;;
&quot;-a&quot;|&quot;-all&quot;)
# recalls self (but not true recursion) to perform
# the full sequence of tasks
${0} sub-cmd-a
${0} sub-cmd-b
;;
*)
# print help
esac
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top