Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: unshift
- X-seq: zsh-users 29762
- From: Ray Andrews <rayandrews@xxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: unshift
- Date: Tue, 2 Apr 2024 07:01:25 -0700
- Archived-at: <https://zsh.org/users/29762>
- In-reply-to: <g2vtktccrjcrgdlvvb4i2cbum7e4zfxi7ffp5wn2gonoeifugt@umeaansa3itu>
- List-id: <zsh-users.zsh.org>
- References: <f1e0b92a-07b6-46c0-a2d6-6eeda828620b@eastlink.ca> <g2vtktccrjcrgdlvvb4i2cbum7e4zfxi7ffp5wn2gonoeifugt@umeaansa3itu>
On 2024-04-02 05:41, Dennis Eriksen wrote:
Why not just use 'elif'? :)
shift
while [ "$1" ]; do
if [ a ]; then b; c;
elif [ d ]; then e; f;
elif [ g ]; then h; i;
fi
shift
done
If 'a' matches, the rest of the conditional won't run.
Good idea but in my particular case there's a block of code half way
down the loop that applies to everything below it. I should have shown
that in my original. Or as I have it now:
while [ "$2" ]; do
shift
if [ a ]; then b; c; continue fi
if [ d ]; then e; f; continue fi
code-applies-to-all-below; more(of-the-same)
if [ g ]; then h; i; continue fi
if [ j ]; then k; l; continue fi
done
... so elif won't work. Yeah, I should have made that clear from the
start, it's what narrows the field of possible solutions.
You could even use 'case'
shift
while [ "$1" ]; do
case $1 in
a) b; c;;
d) e; f;;
g) h; i;;
esac
shift
done
The execution terminates on ';;'.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author