From owner-freebsd-questions@freebsd.org Thu Dec 5 15:02:01 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 D32501CB9F3 for ; Thu, 5 Dec 2019 15:02:01 +0000 (UTC) (envelope-from galtsev@kicp.uchicago.edu) Received: from kicp.uchicago.edu (kicp.uchicago.edu [128.135.20.70]) by mx1.freebsd.org (Postfix) with ESMTP id 47TJpc6YnGz4HxS for ; Thu, 5 Dec 2019 15:02:00 +0000 (UTC) (envelope-from galtsev@kicp.uchicago.edu) Received: from point.uchicago.edu (point.uchicago.edu [128.135.52.6]) (Authenticated sender: galtsev) by kicp.uchicago.edu (Postfix) with ESMTPSA id BAB4E4E61A for ; Thu, 5 Dec 2019 09:01:58 -0600 (CST) Subject: Re: Counter in sh inside loop, value "encapsulation" To: freebsd-questions@freebsd.org References: <20191204181300.8dd0e03c.freebsd@edvax.de> <20191205051145.78f9a805.freebsd@edvax.de> <20191205073531.cb2a23ac.freebsd@edvax.de> From: Valeri Galtsev Message-ID: <41e9293d-eb85-6476-8a23-198c6b5a477e@kicp.uchicago.edu> Date: Thu, 5 Dec 2019 09:01:58 -0600 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:68.0) Gecko/20100101 Thunderbird/68.2.1 MIME-Version: 1.0 In-Reply-To: <20191205073531.cb2a23ac.freebsd@edvax.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 47TJpc6YnGz4HxS X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=uchicago.edu (policy=none); spf=none (mx1.freebsd.org: domain of galtsev@kicp.uchicago.edu has no SPF policy when checking 128.135.20.70) smtp.mailfrom=galtsev@kicp.uchicago.edu X-Spamd-Result: default: False [-1.70 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; DMARC_POLICY_SOFTFAIL(0.10)[uchicago.edu : No valid SPF, No valid DKIM,none]; NEURAL_HAM_MEDIUM(-0.97)[-0.972,0]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-0.99)[-0.989,0]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-questions@freebsd.org]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; IP_SCORE(0.16)[ip: (0.45), ipnet: 128.135.0.0/16(0.22), asn: 160(0.18), country: US(-0.05)]; RCVD_IN_DNSWL_NONE(0.00)[70.20.135.128.list.dnswl.org : 127.0.10.0]; R_SPF_NA(0.00)[]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:160, ipnet:128.135.0.0/16, country:US]; 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 15:02:01 -0000 On 2019-12-05 00: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). Thank you! You took some rust off my use of sh (I usually write scripts in bash). Valeri > > I have no idea why I didn't think of this in the first place... :-) > > > -- ++++++++++++++++++++++++++++++++++++++++ Valeri Galtsev Sr System Administrator Department of Astronomy and Astrophysics Kavli Institute for Cosmological Physics University of Chicago Phone: 773-702-4247 ++++++++++++++++++++++++++++++++++++++++