Created
October 9, 2019 09:36
-
-
Save f-steff/e3e63078f37cf061f580d203c8738a06 to your computer and use it in GitHub Desktop.
Goto in bash - Brilliant for debugging!!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# GOTO for bash, https://stackoverflow.com/questions/9639103/is-there-a-goto-statement-in-bash/52872489#52872489 | |
# Based upon https://stackoverflow.com/a/31269848/5353461 | |
function goto | |
{ | |
local label=$1 | |
cmd=$(sed -En "/^[[:space:]]*#[[:space:]]*$label:[[:space:]]*#/{:a;n;p;ba};" "$0") | |
eval "$cmd" | |
exit | |
} | |
start=${1:-start} | |
goto "$start" # GOTO start: by default | |
#start:# Comments can occur after labels | |
echo start | |
goto end | |
# skip: # Whitespace is allowed | |
echo this is usually skipped | |
# end: # | |
echo end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment