From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 2A46120FC3 for ; Mon, 1 Apr 2024 16:01:02 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1711980062; b=WLvI19FclARYDaaBCUkf4dmVisYyw1vdt+l76T/cSzK3taqvoDtERR9igu7DwtQnb1pimgMpZb 4L5j6S7RkcfObqcXLaXz/nIqe7/6HKe2bUjKMKKIsMs1TqraPXgLpGxjXuD80E3xiTIFuViH5p TQ7DgHMsi2eWPWqCWwfqSwM8+XBnldSmXRgYqZfjd/DW9TB3j3tNm8Iluxg6couFAsXkOyD+1e WAhVGl5i3mCObBZEac3HMhmdyFkoehhd3+p9IbGCJX6wmacmj8Saz6KwAhS3f6D9f6gFzdbBkD jRFEu+FNz7hauHofllHTA2swdjPL9Dd+ubUrHtcA9X9ZYQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lj1-f175.google.com) smtp.remote-ip=209.85.208.175; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1711980062; bh=cnR9/ODRPQK2ps0QLtOFGhYfUAs48rEfZMJdPbyu7o0=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=WuFEbZW3xznjVnKyK/Q9Lg47TxJmmdkMebcfdsw+xIqKY0RL6+fFmqkpHJbvdWoUFvdZuPfBrb NyQFAcc7ok6EKt/qV4+5UP7fEUF3v7582xh0MBSu0iyc43/UNuoJsds8Mb/fHvEc9kietGsFJU RBBhei4c/rwGaqax1UV5CidZDp8ZuyLZnKe8EQiExQGS9/WiE8Yy073olL/GQ8pehG6BamaK6T tnPZ189QjQsOcoyLv23hyRVsfR+Xpl/TekIiAGOW7d7yeqOL13mGKqX8pWgBes59pZo8S1E0hb bLlVmR/Cgni55njqsmcLyuYfqrJ69H6MnJQEu3yVm1zHHA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=/xwi4sHDhKDsnznGQB359fB3U2+U8K2RGHJVFacwCh0=; b=DATXyrMdSn2xwkKVG60Wev+wMA qBEvkQ+trG2h0NLZWaYHdCsM6tbcR51Fn3y00aakSOdCttQWwf8NTOFbS8+sfrMaoqiHbysM/x6RP iO8gyw7ic1bsArV0qDofy3FuQpwoqPjZ8DEWPEGkGwGj92atHSLl8Ycjb0zP3gx9NbWbtVXKSLtGQ KNwkyv6f4DJ9WRhml7XRdWvgNI3g9lGpwR9P4W0JRgiRv/fw7fFHYFCjaYsOnAHwjIFV/tTzOy8pz fUoMoPDIMj7+d55c7DsZ9RLRBiVWcm4nnkoH3xpFwYPUBeMa9ID1Rnghgq7Q0hW5h5RrzJuM8d4uh zqIsol1A==; Received: by zero.zsh.org with local id 1rrIDe-0003r8-Lv; Mon, 01 Apr 2024 14:01:02 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lj1-f175.google.com) smtp.remote-ip=209.85.208.175; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lj1-f175.google.com ([209.85.208.175]:61488) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rrI7r-0002ri-AT; Mon, 01 Apr 2024 13:55:03 +0000 Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2d6ff0422a2so56700621fa.2 for ; Mon, 01 Apr 2024 06:55:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711979702; x=1712584502; darn=zsh.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=/xwi4sHDhKDsnznGQB359fB3U2+U8K2RGHJVFacwCh0=; b=YGimofIOMeclWh42PTjYTdY6gRnZ/6bqnr+ALqavR7D2/RMZwk/ootoCE8xRrCYNX5 2ERwB9xyqUNcczifETa4k0uXajHgoqzb3cAW52pH+cSNTxEm5Magn5ikX8hI7c0qNguO l7VjEMAQ53PG+g3tNy8qzShH67eBdCGKek4mhWHVzNQ4zypWqztXgW9ybvdkv2JsY5dd HcKgpJ8F72CoDT3bpdk6o49zy99Py7yfh18fcl6XD6lx5CWTYndNl+6856IlgXwWNZLQ CR3sCdvhQ6UhKl/EESMjN+wiAbb9h8J771eCHWwvLeq/DXkBo0m1iE3tziCV61Pr0hqe RIAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711979702; x=1712584502; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/xwi4sHDhKDsnznGQB359fB3U2+U8K2RGHJVFacwCh0=; b=ldyxB/ZXhGVnhNrFPFjWJeoNrdMXUKd3gIzwGIwSxMVsyBY1VstIiKiJYShQ54gdPR ze/e0jPkx3tCNPPEOch9ETRTaqaiLbvMrCK3itWSdOq+l2m59pVIAN5PXVRyathis26l heqwEJVQSchk6lhR88HJj8iY0Tp9m0w+IjsK1zDA1t8esKajTpjrx6v03o26GgiaceuU zshNSk8/cvayKpzWbtHeAH9A6Xeiq2VMDovu4pJ5BiK52OTvuWXcoh5dxBpM1H/v3lBG NiTwzyOeuV0g8Dh63amHV48QqIai5gclqFI8FW/oohMpFXDZB3/3InGGpt5ZF9mUBtaL lNdg== X-Gm-Message-State: AOJu0Yx+z+I2jIaTaSuslA82qDYEORf9LIZ2tc67Q8wIwkSYEfyR9TXH igAXVhB7/nla537gLh2EXHPhrsazQvu5hePOq5GFiggFxPcz+2SvdDB4Hahbr+kOnn924cCiJOj QxhsD53UWlbBObao5t2e72nsy8dNHKGch X-Google-Smtp-Source: AGHT+IEaEIHZLK7PfDt3WMDFZ2/DxSuL841uq2DSQWz4t3omxfwxIvnffPrqtCY3IokBUqoofMnls39Rbb90cIQWa8E= X-Received: by 2002:a2e:9003:0:b0:2d6:f100:6e6b with SMTP id h3-20020a2e9003000000b002d6f1006e6bmr6223935ljg.18.1711979702260; Mon, 01 Apr 2024 06:55:02 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: "Mark J. Reed" Date: Mon, 1 Apr 2024 09:54:49 -0400 Message-ID: Subject: Re: unshift To: Ray Andrews Cc: Zsh Users Content-Type: multipart/alternative; boundary="000000000000041bae06150956ab" X-Seq: 29747 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: --000000000000041bae06150956ab Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I haven't read your whole message yet, but to unshift a new value in front of the positional params, all you have to do is this: set -- "$new" "$@" And now $1 is "$new", $2 is whatever $1 used to be, and so on. On Mon, Apr 1, 2024 at 9:52=E2=80=AFAM Ray Andrews = wrote: > Can we unshift the positional params? I have a complex function that has > shifts throughout and at one point there's a while loop: > > shift > while [ "$1" ]; do > if [ a ]; then b; c fi > if [ d ]; then e; f fi > if [ g ]; then h; i fi > ... > shift > done > > ... works fine, but I'm thinking to restructure it: > > 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 remainin= g > 'if' tests might even do some bad stuff. The problem of course is that i= f > I 'continue', the final 'shift' is missed. I could do this: > > # shift > while [ "$2" ]; do > shift > if [ a ]; then b; c; continue fi > if [ d ]; then e; f; continue fi > if [ g ]; then h; i; continue fi > ... > # shift > done > > ... except that the leading (commented) 'shift' might happen in any numbe= r > of places and changing them all would be troublesome. It can be done of > course, but I'm wondering if we have some way of faking this: > > shift > unshift > while [ "$1" ]; do > shift > if [ a ]; then b; c; continue fi > if [ d ]; then e; f; continue fi > if [ g ]; then h; i; continue fi > ... > # shift > done > > ... it looks pointless above, however note that the leading 'shift' might > in fact have happened in any one of several different places all of which > would need to be reworked and it's fragile, so the 'unshift' would take > care of it in one place, at least temporarily. I know we don't have an > official unshift, but can it be faked? Of course there's also this: > > ... > if [ a ]; then b; c; shift; continue fi > ... > > ... but I'm wondering about a more succinct logic. The quick and dirty > 'unshift' idea would solve a temporary problem very nicely. > > > > --=20 Mark J. Reed --000000000000041bae06150956ab Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I haven't read your whole message yet, but to unshift = a new value in front of the positional params, all you have to do is this:<= div>

=C2=A0 =C2=A0 se= t -- "$new" "$@"

And no= w $1 is "$new", $2 is whatever $1 used to be, and so on.

On = Mon, Apr 1, 2024 at 9:52=E2=80=AFAM Ray Andrews <rayandrews@eastlink.ca> wrote:
=20 =20 =20
Can we unshift the positional params?=C2=A0 = I have a complex function that has shifts throughout and at one point there's a while loop:

shift
while [ "$1" ]; do
=C2=A0=C2=A0=C2=A0 if [ a ]; then b; c=C2=A0 fi
=C2=A0=C2=A0=C2=A0 if [ d ]; then e; f=C2=A0 fi
=C2=A0=C2=A0=C2=A0 if [ g ]; then h; i=C2=A0 fi
...
shift
done

... works fine, but I'm thinking to restructure it:

shift
while [ "$1" ]; do
=C2=A0=C2=A0=C2=A0 if [ a ]; then b; c; continue fi
=C2=A0=C2=A0=C2=A0 if [ d ]; then e; f; continue fi
=C2=A0=C2=A0=C2=A0 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.=C2=A0 The problem of course is that if I 'continue'= ;, the final 'shift' is missed.=C2=A0 I could do this:

# shift
while [ "$2" ]; do
=C2=A0=C2=A0=C2=A0 shift
=C2=A0=C2=A0=C2=A0 if [ a ]; then b; c; continue fi
=C2=A0=C2=A0=C2=A0 if [ d ]; then e; f; continue fi
=C2=A0=C2=A0=C2=A0 if [ g ]; then h; i; continue fi
...
# shift
done

... except that the leading (commented) 'shift' might happen in any number of places and changing the= m all would be troublesome.=C2=A0 It can be done of course, but I'm won= dering if we have some way of=C2=A0 faking this:

shift
unshift
while [ "$1" ]; do
=C2=A0=C2=A0=C2=A0 shift
=C2=A0=C2=A0=C2=A0 if [ a ]; then b; c; continue fi
=C2=A0=C2=A0=C2=A0 if [ d ]; then e; f; continue fi
=C2=A0=C2=A0=C2=A0 if [ g ]; then h; i; continue fi
...
# shift
done

... it looks pointless above, however note that the leading 'shift' might in fact have happened in any one of several different places all of which would need to be reworked and it's fragile, so the 'unshift' would take care of it in one place,= at least temporarily.=C2=A0 I know we don't have an official unshift= , but can it be faked?=C2=A0 Of course there's also this:

=C2=A0=C2=A0=C2=A0 ...
=C2=A0=C2=A0=C2=A0 if [ a ]; then b; c; shift; continue fi
=C2=A0=C2=A0=C2=A0 ...

... but I'm wondering about a more succinct logic.=C2=A0 The quic= k and dirty 'unshift' idea would solve a temporary problem very nic= ely.=C2=A0





--
Ma= rk J. Reed <mar= kjreed@gmail.com>
--000000000000041bae06150956ab--