From owner-freebsd-questions@freebsd.org Thu Dec 5 11:03:33 2019 Return-Path: Delivered-To: freebsd-questions@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 78D881C5E78 for ; Thu, 5 Dec 2019 11:03:33 +0000 (UTC) (envelope-from freebsd@qeng-ho.org) Received: from bede.qeng-ho.org (bede.qeng-ho.org [217.155.128.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 47TCWS4C3Xz44ty for ; Thu, 5 Dec 2019 11:03:32 +0000 (UTC) (envelope-from freebsd@qeng-ho.org) Received: from arthur.home.qeng-ho.org (arthur.home.qeng-ho.org [172.23.1.2]) by bede.qeng-ho.org (Postfix) with ESMTP id 174DB10375; Thu, 5 Dec 2019 11:03:25 +0000 (GMT) Subject: Re: Counter in sh inside loop, value "encapsulation" To: Polytropon , freebsd-questions@freebsd.org References: <20191204181300.8dd0e03c.freebsd@edvax.de> <20191205051145.78f9a805.freebsd@edvax.de> <20191205073531.cb2a23ac.freebsd@edvax.de> From: Arthur Chance Message-ID: <798639b5-75fb-a82f-c024-4eee8d55e1c5@qeng-ho.org> Date: Thu, 5 Dec 2019 11:03:24 +0000 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0 MIME-Version: 1.0 In-Reply-To: <20191205073531.cb2a23ac.freebsd@edvax.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 47TCWS4C3Xz44ty X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of freebsd@qeng-ho.org designates 217.155.128.241 as permitted sender) smtp.mailfrom=freebsd@qeng-ho.org X-Spamd-Result: default: False [-4.78 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:217.155.128.240/29]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; RCVD_TLS_LAST(0.00)[]; DMARC_NA(0.00)[qeng-ho.org]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; IP_SCORE(-2.48)[ip: (-7.64), ipnet: 217.155.0.0/16(-3.82), asn: 13037(-0.84), country: GB(-0.08)]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:13037, ipnet:217.155.0.0/16, country:GB]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Dec 2019 11:03:33 -0000 On 05/12/2019 06:35, Polytropon wrote: > For further reference, the simple solution is always the best one. > I now have the following: > > COUNT=0 > for URL in `grep "^https" ${INFILE}`; do > process ${URL} > if [ $? -eq 0 ]; then > COUNT=`expr ${COUNT} + 1` > fi > done > echo "URLs processed: ${COUNT}" > > There now is no piping step (and therefore no subshell) involved. > This works and can be easily extended (more preprocessing from > the input list file). > > I have no idea why I didn't think of this in the first place... :-) > A minor point: you can replace COUNT=`expr ${COUNT} + 1` with COUNT=$((COUNT + 1)) to use arithmetic expansion rather than spawning a subshell for the backticks. -- What do we want? A time machine! When do we want it? Errm ...