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.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 32421 invoked from network); 16 Apr 2021 10:13:25 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 16 Apr 2021 10:13:25 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1618568005; b=xeDhdNl/2fuBp5et+hUMf5tPZL3aFga50ctkRWgYBel7W09KNk26ynuvONQlgzGjnGxGch13oC u9Rr6GSWFYaxq3tkZvaArfXJ5fOqneApx+TQeGZzeyKg5XS8PwAvXShf111z//56nbPTVucmEn qMW9jl5My5tcVJN8oVlkCLSzh4CxhePrI64liCPVYERtr/jLRgh42sPe01T3qz1Tf46ZeArJeF Xajrp0Ze3f/s2ugLJgMCnTm+eziLj/po+dc1EuW/wfgxweBDCotPJmT4R+7v9q25y6FheRtp10 A19vT7zXRAZoCg/ASPmKRQGuqUzak3uGiKh4lZupYNVeGA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay3-d.mail.gandi.net) smtp.remote-ip=217.70.183.195; dmarc=none header.from=chazelas.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1618568005; bh=+5id1/cWCInQS57Z7l+qObezCV8gw7+iEiWtaQTvTI8=; 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; b=qjXMwH2a44vgMAS77ZyyH2Jq5viXlWzXU81esmKmxYY4fON8MA+HczoHQj/ds2MbF+IhthptGN 20+I2Mzhf20bjHq98xutcyxOfBniPXNaN402SgQG38xW1kHT3Rr+o4eV7k9ujQHEUGVhKdMuR8 31w4I6ipZzMSezt9c5MRpwHlz8Usx48g731+bU/JbuyfzFBqEDLQHiU6pXtpFwJmlhYadnBaIP Ti/0FCDpYmJh8nsPkD1Pfzt3KodBgMeMPExDIF90gqKxX2huG9ZowRonGf+w/j9TBAjEsxAr9i yh5KK1HVrULL6IlHWVWOf7B/edhXbqmjKKcr/Cfs8stT+w==; 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=aUObPVJbQTXgiTPHgpwoSiX29LDXmAywYM5J9pCCZ9I=; b=p6o2zd0MyoIP2Rui7bHPmWDQ3i jCGrB7XXS7hOwjqCjsICViOA2cbYabxLJwQvIxESs/34wH3JEu/O3c5nK8SQCl91nUGyEAjTgbFil OVQIn7rJZ+cEdfgEL8jSTfrY8eKDia3bywQpVz1MLJupNmA/sYH7O846W7FP1cMK0eoObzpDr1HSg 0XYiLKcES7c627iJMbdfl4VEvRdIiI09yLJF1OumbNC0fB881fvceB/PlmWfdaKY1eV3PatSUiRUZ TDgSc/s4C7TTLskAw3BOrwk7q2TjtXcYweAAW0FVoWhLNi5MXFutDYQkVtMOuYhklpXl619kt5ZKu Urkr5KFA==; Received: from authenticated user by zero.zsh.org with local id 1lXLTX-000HlU-NJ; Fri, 16 Apr 2021 10:13:23 +0000 Authentication-Results: zsh.org; iprev=pass (relay3-d.mail.gandi.net) smtp.remote-ip=217.70.183.195; dmarc=none header.from=chazelas.org; arc=none Received: from relay3-d.mail.gandi.net ([217.70.183.195]:44069) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1lXLSu-000HAv-Cz; Fri, 16 Apr 2021 10:12:45 +0000 X-Originating-IP: 90.215.204.106 Received: from chazelas.org (unknown [90.215.204.106]) (Authenticated sender: stephane@chazelas.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 9A4136000A; Fri, 16 Apr 2021 10:12:42 +0000 (UTC) Date: Fri, 16 Apr 2021 11:12:41 +0100 From: Stephane Chazelas To: Daniel Shahaf Cc: Zsh Users , zzapper Subject: Re: alias with a parameter Message-ID: <20210416101241.yv3zr55rziornpg3@chazelas.org> Mail-Followup-To: Daniel Shahaf , Zsh Users , zzapper References: <2902540a-9c07-4423-b0bb-6802af6e97a2@www.fastmail.com> <48bef9cb-fea7-1a17-96b1-dd4ae7bf54aa@spamtrap.tnetconsulting.net> <20210409224930.GB6760@tarpaulin.shahaf.local2> <41baeb56-de2f-2fb2-3544-ce703bf96223@rayninfo.co.uk> <6717f359-f340-a436-c2dd-1b9ae19d345a@rayninfo.co.uk> <20210415203046.GB6669@tarpaulin.shahaf.local2> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210415203046.GB6669@tarpaulin.shahaf.local2> X-Seq: 26667 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: 2021-04-15 20:30:46 +0000, Daniel Shahaf: > Bart Schaefer wrote on Thu, Apr 15, 2021 at 11:19:16 -0700: > > On Wed, Apr 14, 2021 at 4:10 AM zzapper wrote: > > > if [ $# -gt 0 ] ; then > > > > It's generally preferable to use [[ ... ]] instead of [ ... ] because > > "[" is just another name for "test" and "]" is just one of its > > arguments, whereas "[[" and "]]" are syntax tokens with parsing rules > > for what appears between them. However, since you're comparing > > numbers, you could use (( $# > 0 )) here. > > In general, «(( ${+foo[1]} ))» is faster than «(( ${#foo} ))», because > the latter takes O(N) time where N is the length of the array, where's > the former is O(1). Beware that (( ${+foo[1]} )) approach doesn't work when the ksharrays option is enabled. (though I'd expect one would generally only use that option as part of the ksh emulation to interpret ksh code, so that would likely not be a problem). It also does't work for associative arrays. FWIW, [[ -v foo[1] ]] seems to be slightly faster. I'd still use (( $#foo )) or (( $#foo > 0 )) for legibility. -- Stephane