[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: problem anomalies , possibly aliases related
From: |
Greg Wooledge |
Subject: |
Re: problem anomalies , possibly aliases related |
Date: |
Thu, 20 Jul 2023 14:09:13 -0400 |
On Fri, Jul 21, 2023 at 12:33:07AM +1000, Martin D Kealey wrote:
> C has longjmp, and other languages have exceptions. Non-local break is a
> usable "Bash shaped" analogue of those. Not perfect, sure, but close enough
> to be useful. (Non-local continue is a logical extension of that.)
>
> Saying that this *ought* to be done using aliases is not reasonable, as it
> means forgoing the other stuff that functions can do, like taking
> parameters, declaring local variables, or returning a status.
Well in any case, the behavior you wanted is not reliable across shells,
nor even across versions of bash.
unicorn:~$ cat foo
f() { echo f; break; }
for i in 1 2 3; do
echo "$i"
f
done
unicorn:~$ bash-4.3 foo
1
f
unicorn:~$ bash-4.4 foo
1
f
foo: line 1: break: only meaningful in a `for', `while', or `until' loop
2
f
foo: line 1: break: only meaningful in a `for', `while', or `until' loop
3
f
foo: line 1: break: only meaningful in a `for', `while', or `until' loop
unicorn:~$ dash foo
1
f
2
f
3
f
unicorn:~$ ksh foo
1
f
2
f
3
f
Since it's not possible to do it this way portably, I suggest that the
alias alternative would be the way to go.
- problem anomalies , possibly aliases related, alex xmb ratchev, 2023/07/20
- Re: problem anomalies , possibly aliases related, Martin D Kealey, 2023/07/20
- Re: problem anomalies , possibly aliases related, Grisha Levit, 2023/07/20
- Re: problem anomalies , possibly aliases related, alex xmb ratchev, 2023/07/20
- Re: problem anomalies , possibly aliases related, Martin D Kealey, 2023/07/20
- Re: problem anomalies , possibly aliases related, Greg Wooledge, 2023/07/20
- Re: problem anomalies , possibly aliases related, Martin D Kealey, 2023/07/20
- Re: problem anomalies , possibly aliases related,
Greg Wooledge <=
- Re: problem anomalies , possibly aliases related, alex xmb ratchev, 2023/07/21
- Re: problem anomalies , possibly aliases related, Greg Wooledge, 2023/07/21
- Re: problem anomalies , possibly aliases related, alex xmb ratchev, 2023/07/21
- Re: problem anomalies , possibly aliases related, Martin D Kealey, 2023/07/21
- Re: problem anomalies , possibly aliases related, Phi Debian, 2023/07/22
- Re: problem anomalies , possibly aliases related, alex xmb ratchev, 2023/07/20