From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 2609 invoked from network); 14 Apr 2021 13:04:54 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 14 Apr 2021 13:04:54 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1618405494; b=tg7Xczm9ImmmmH81RmXm7To0a6h39RmAUXksNFI9qqMHua2UResOnxDJCwtTfnKNWejviGSWcd Ym2qxezUMUuv6p191Z6GkofYtJuHsqCAfw5kgVFXKJEmRTO6M/WVrPFodbCCcQ1zfrudtdaH0q HhkkyARSjsw7V/eJV2oE9WRtPS0MOlWs0hWPA06Pk8DvbCWixXkha450HXKIeTT+2EcZJNVHWM O72MMDBI5KpYN34fdKf2GWhIgxffr8yNaqIPFIGaFchv8CG+2IbZDkUE0S9lFPgNNIrBJFARu8 NZtzwbzRN6+70TQNcfRODMrpNfJ1BShl2KxOnF90Vb1SKQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (wout5-smtp.messagingengine.com) smtp.remote-ip=64.147.123.21; dkim=pass header.d=daniel.shahaf.name header.s=fm3 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm2 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1618405494; bh=aYQqQ4nCBPv/0nowMeZBpfADul1amqoIS4hpQ2rrPQw=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:DKIM-Signature: DKIM-Signature:DKIM-Signature; b=pATVF4i/gWzqP9sVj9ZRwNq2U2Q7/IVeotedNeFhrOKxsDg+EoxU8+MpcRl40C5G1bgpSFT2lK ec14lXlKP92Yc8ZP+75do3N5IRAOa85dAbSUHDRqV5UkJoCtiU9v4ZC60Y/wKBDF44ZZzP2i3y 11AwqMfW97Xal8pt5x4GdJS5EA5Vel/SOtPgTvXAbgClEsmHKbpDhBatPoDYiQPmIrRJ8jS2mr d3tfOJWFmFDwpoF6LnzzFh58/0wwqUZPUl8M4PppZ73RUpDLhVEITNrNsdD4bPuRsqqlJ+gey4 YURvy528ywpN1OxPCXs1swm1xzLJtd7IXtKEQJkRH5ElNg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=kT5WHElfV0GoAW0O1m7a57bq0DNh0KPPXXsXzXiH8nI=; b=0sM5fOiBn6g8UGqhxeZUAi5FYM cvhRD7d8+NR0a59KdlR33O0K3euCm9JGXhN3jUYKnEsQ2JWhvG/UNcNjE15Z+eza3PJDlMKSgcypI K1ThA2fpxqmrYlpzsPQHsDdd6Y1Sg2YRDdQZ0ROt6PI57S9Kc23MXgrbAVmylqPXAuo5gKNKK0pwa Oyc2jnOgp4rI8aUeYgel3Lqmkd6nR9C+sYBjO22bh4llCPdaRqz5onpp2+UBjsoKb1Ajeam5ZJQ1k d/hiAYUccONBb2GLWOYV76U/kcy+Tqg6iuq7WCQN2tqTPL1ZUZ8zkrrBPpcsJuK80BPYHpqvhjzYC dzWQ35DQ==; Received: from authenticated user by zero.zsh.org with local id 1lWfCQ-0002Gn-MA; Wed, 14 Apr 2021 13:04:54 +0000 Authentication-Results: zsh.org; iprev=pass (wout5-smtp.messagingengine.com) smtp.remote-ip=64.147.123.21; dkim=pass header.d=daniel.shahaf.name header.s=fm3 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm2 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none Received: from wout5-smtp.messagingengine.com ([64.147.123.21]:39813) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1lWfC4-00020y-Dq; Wed, 14 Apr 2021 13:04:33 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 7B7C61989; Wed, 14 Apr 2021 09:04:30 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Wed, 14 Apr 2021 09:04:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:cc:subject:message-id :references:mime-version:content-type:content-transfer-encoding :in-reply-to; s=fm3; bh=kT5WHElfV0GoAW0O1m7a57bq0DNh0KPPXXsXzXiH 8nI=; b=yewOoasYgsL1yuLjPvVF5WImze5zkHb1MIFihSgl0ULc7ERRrNVNBzX4 Li+l3zHAdPSHYq7Kj28WeTE7dkGT3ybWbP8svtIZ+X7L+in3bwPjKmhuIXAX9NCY lP9PFKQAqf8JEUhzYkux3w+Sg7P71Lg159JsCrA8RUWNbyWSngeV4vC+4nVIecIr Z0n8+ATaiyX5HV2ZKN8eS0xV9CQ1VlNNyo36tlL7+gHuMg6GlsTNuQcIQlGhkmbZ mo8KPbWm+RSxatAxZEiyltXtTwmX6mVhWLqnZx937PZU+2AqSgLZMGRJBYYipCS/ jSmZ2WIJ+g7Qw/Lle4cNmkFmwW5+/Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=kT5WHElfV0GoAW0O1m7a57bq0DNh0KPPXXsXzXiH8 nI=; b=JI/5ym4XVnkqpoKsl3JfhJuYBYzK9/jR1J9Ut7MHAJjOaqzCcX3AJE4ya LoiQ9UpgAmy4oRKHGNpua3FBOUIjr5/nr/b3lC/3xOWPJyWz5CncFLHWJBaU1XvH suA1qPRZHfunglmX3hC91fb879aSQi/gIwaJWOaCK42mnD0CeWjmiUDIXHsy4DRl wONiO9Gbko6Z/Zi3XqP5gOdpOjEzC1JIuIKzkq0X5qLJGo6AGKq2gOBpxmkD3ILm MgT57Wi1JpREhLCE9O2CrpUTYw7tvpL+lMygrUvce14u7rOmh1jMqjDVoFrh8rMa BX3nuK1/ysBsqzhdD4j56iTFYZsmw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudeluddgiedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggugfgjfgesth ektddttderudenucfhrhhomhepffgrnhhivghlucfuhhgrhhgrfhcuoegurdhssegurghn ihgvlhdrshhhrghhrghfrdhnrghmvgeqnecuggftrfgrthhtvghrnhepgfelhedtffeuhf egueelfeffjeegtddtleehvddvueeihfevgfdvgffhvedvkeetnecukfhppedutdelrdei iedrieefrddvfedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepugdrshesuggrnhhivghlrdhshhgrhhgrfhdrnhgrmhgv X-ME-Proxy: Received: from tarpaulin.shahaf.local2 (bzq-109-66-63-230.red.bezeqint.net [109.66.63.230]) by mail.messagingengine.com (Postfix) with ESMTPA id 3354E108005C; Wed, 14 Apr 2021 09:04:29 -0400 (EDT) Received: by tarpaulin.shahaf.local2 (Postfix, from userid 1000) id 4FL2k33Frfz43s; Wed, 14 Apr 2021 13:04:27 +0000 (UTC) Date: Wed, 14 Apr 2021 13:04:27 +0000 From: Daniel Shahaf To: dana Cc: Zsh hackers list , franciscodezuviria@gmail.com Subject: Re: [BUG] getopts OPTIND - yash's behaviour Message-ID: <20210414130427.GE3882@tarpaulin.shahaf.local2> References: <0877C4E8-4CA3-453F-A16B-99E576F60E8D@dana.is> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Seq: 48567 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: dana wrote on Tue, Apr 13, 2021 at 18:28:50 -0500: > + # This function is written so it can be easily referenced against other shells > + t() { > + local o i=0 n=$1 > + shift > + while [ $i -lt $n ]; do > + i=$(( i + 1 )) > + getopts a: o "$@" 2> /dev/null > + done > + printf '<%d>' "$OPTIND" > + } > + # Try all these the native way, then the POSIX_BUILTINS way > + for 1 in no_posix_builtins posix_builtins; do ( > + setopt $1 > + print -rn - "$1: " > + <3> t 1 -a I'm guessing yash notices that -a (at index 1) takes an argument, so it goes to the top of the loop for the word at index 2, where it increments OPTIND before noticing that index 2 is actually past the end of the array. > + <3> t 1 -w I get "1:2" in yash 2.51 interactively. > + <3> t 2 -a -w Consistent with other shells. > + <7> t 4 -a -w -e -r -a - The first word is the -a option. - The second word is the argument to the -a option. - The third word is -w, so this call will return an error. Before returning, since the next word to parse is the fourth one, set OPTIND to 4. > + <7> t 5 -a -w -e -a -w -e Consistent with other shells. > + <7> t 5 -a -w -e -r -ax -a Consistent with other shells. > + print > + ); done > +0:OPTIND calculation with and without POSIX_BUILTINS (workers/42248) > +>no_posix_builtins: <1><1><3><5><7><6> > +>posix_builtins: <2><2><3><6><7><7> > >