zsh-users
 help / color / mirror / code / Atom feed
From: Dennis Eriksen <d@ennis.no>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: unshift
Date: Tue, 2 Apr 2024 14:41:16 +0200	[thread overview]
Message-ID: <g2vtktccrjcrgdlvvb4i2cbum7e4zfxi7ffp5wn2gonoeifugt@umeaansa3itu> (raw)
In-Reply-To: <f1e0b92a-07b6-46c0-a2d6-6eeda828620b@eastlink.ca>

Hi,

On Mon, Apr 01, 2024 at 06:52:00AM -0700, Ray Andrews wrote:
>shift
>while [ "$1" ]; do
>    if [ a ]; then b; c; continue fi
>    if [ d ]; then e; f; continue fi
>    if [ g ]; then h; i; continue fi
>...
>shift
>done
>
>... because only one 'if' test will be relevant per loop and the
>remaining 'if' tests might even do some bad stuff.  The problem of
>course is that if I 'continue', the final 'shift' is missed.

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.

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 ';;'.

-- 
Dennis Eriksen


  parent reply	other threads:[~2024-04-02 12:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-01 13:52 unshift Ray Andrews
2024-04-01 13:54 ` unshift Mark J. Reed
2024-04-01 14:00   ` unshift Mark J. Reed
2024-04-01 14:23   ` unshift Ray Andrews
2024-04-01 16:03   ` unshift Stephane Chazelas
2024-04-01 14:38 ` unshift Roman Perepelitsa
2024-04-01 16:11   ` unshift Ray Andrews
2024-04-01 16:20     ` unshift Roman Perepelitsa
2024-04-01 16:40       ` unshift Ray Andrews
2024-04-01 19:41         ` unshift Bart Schaefer
2024-04-01 22:52           ` unshift Ray Andrews
2024-04-01 16:03 ` unshift Bart Schaefer
2024-04-01 16:30   ` unshift Ray Andrews
2024-04-02 12:41 ` Dennis Eriksen [this message]
2024-04-02 14:01   ` unshift Ray Andrews
2024-04-02 19:59     ` unshift Roman Perepelitsa
2024-04-02 20:24       ` unshift Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=g2vtktccrjcrgdlvvb4i2cbum7e4zfxi7ffp5wn2gonoeifugt@umeaansa3itu \
    --to=d@ennis.no \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).