after many years, I learned that usually shell scripts are only good for the most basic of uses. here is a similar program in Go that doesn't require any hacks:
package main
import "os"
func main() {
var x int
switch len(os.Args) {
case 1: goto start
default:
switch os.Args[1] {
case "foo": goto foo
case "mid": goto mid
}
}
start:
x = 100
goto foo
mid:
x = 101
println("This is not printed!")
foo:
if x == 0 { x = 10 }
println("x is", x)
}