restart parameter

I have a shell script with 4 separate functions taking place, one after the other.
Is there a way to introduce a parameter so that if the job fails, then I can restart it at a specific point in the script ?
Ideally, the default will be null (or 1), so that it will not normally be set, and the script will start at the beginning.
But if the script were to fail between stages 2 and 3, say, then the script could be rerun, with the parameter set to 2.
Many thanks

Your scripts should managed flags, so when step 1 is complete, you create a flag

FLAG="/tmp/flagstep2"
touch $FLAG

On the other hand, at the beginning of your script, you should check for the existence of that flag:

[[ -f "$FLAG" ]] && step2 || step 1
step3 && rm "$FLAG"

if found : restart from step 2 else, start from the beginning (step 1).

This flag will be removed after step 3 has completed successfully.

Thanks ctsgmb
For your code to work, should I declare headings in my script,
like step1, step2, step3, step4 ?
If so, do I need special characters around them to make them headings ?
And should there be similar tests after each step and at the begining of the script to send control to step3 or step4 : in your reply only step2 is being catered for ?
Many thanks for your help.

Of course you need to code the step1 step2 ... and so one.

Please post what you did try so far

Hi ctsgnb
Thanks for your contributions, but I now no longer need to string all the scripts together. It will be handy for me to know how to do this in future, though, and so I will do some more testing later on to sus this one out.
Thanks again.