[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Have a equivalent performing of goto
From: |
Greg Wooledge |
Subject: |
Re: Have a equivalent performing of goto |
Date: |
Wed, 12 Jul 2023 11:13:08 -0400 |
On Wed, Jul 12, 2023 at 10:07:34PM +0700, Budi wrote:
> How to equivalently perform goto in Bash ?
You don't.
Rewrite your control logic using while loops, for loops, if statements,
case statements, functions, state variables, etc.
> if ((i=1)) ;then
> goto thisFar
> fi
>
> echo foobar
>
>
> thisFar:
>
> echo go on
So there's a block of code in the middle that you want to skip over,
if some condition is met? Wrap that whole middle section in an "if"
statement. You can also move it to a(nother) function if that'll help
with readability.
local skip=0
if ((i == 1)); then
skip=1
fi
if ((!skip)); then
echo foobar
fi
echo go on