I there a way to run a bash script starting from a specific line?
Assume my script looks like that:
0 #!/bin/bash
1 ...
2 clone a repository
3 ...
4 command that crashed
I go and fix line 4 and I want to rerun the script without running the code from lines 1,2,3 but starting directly from line 4.
I quick search for the title of this question didn't give me an answer. If there is a way to do that with bash it would be useful.
Thank you for the answers. Another solution if you also want to keep some lines in the beginning is:
# assuming you want to run your script except from line 4 to 7
sed '4,7s/^/#/g' -i script.sh; ./sript.sh #this replaces the beginning of the line ^ with # from lines 4 to 7
# to undo the comments
sed '4,7s/^#//g' -i script.sh; ./sript.sh
Try this:
bash <(sed -n '5,$p' script.sh)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With