Created
April 4, 2015 21:15
-
-
Save willkill07/377ea99ed01f44f0cb37 to your computer and use it in GitHub Desktop.
goto in bash (with reverse seeking)
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 | |
# include this boilerplate | |
function jumpto | |
{ | |
label=$1 | |
cmd=$(sed -n "/#$label:/{:a;n;p;ba};" $0) | |
eval "$cmd" | |
exit | |
} | |
start=${1:-"start"} | |
jumpto $start | |
#start: | |
# your script goes here... | |
x=100 | |
jumpto foo | |
#mid: | |
x=101 | |
echo "This is not printed!" | |
jumpto end | |
#foo: | |
x=${x:-10} | |
echo x is $x | |
jumpto mid | |
#end: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment