Bash has no built-in goto statement. A Windows batch example using labels cannot be pasted into a Bash script. Use a function to repeat work or a loop to control repetition.
Call a function
show_message() {
printf "%s\n" "Hello from Bash"
}
show_message
show_messageThis prints the message twice. A function is defined once and runs each time you call its name.
Skip an iteration or leave a loop
for number in 1 2 3 4; do
if [ "$number" -eq 2 ]; then
continue
fi
if [ "$number" -eq 4 ]; then
break
fi
printf "%s\n" "$number"
doneThe output is 1 followed by 3. continue moves to the next iteration; break leaves the loop. Inside a function, return returns control to its caller. exit ends the shell or script instead.
If you meant “go to a directory”
Use cd to change folders. Our Bash navigation guide covers cd .., cd - and the directory stack. If you are entering Linux commands from Windows, first start the intended WSL distribution.
Sources and verification
Both examples are executed in the local Bash verification run. The former article’s invented goto example has been removed.
If your Bash example will not run
Follow the command-not-found checklist when Bash cannot locate the script or command. If it finds the file but rejects execution, check script permissions.
