Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Dec 2019 11:03:24 +0000
From:      Arthur Chance <freebsd@qeng-ho.org>
To:        Polytropon <freebsd@edvax.de>, freebsd-questions@freebsd.org
Subject:   Re: Counter in sh inside loop, value "encapsulation"
Message-ID:  <798639b5-75fb-a82f-c024-4eee8d55e1c5@qeng-ho.org>
In-Reply-To: <20191205073531.cb2a23ac.freebsd@edvax.de>
References:  <20191204181300.8dd0e03c.freebsd@edvax.de> <slrnqug5mi.srf.naddy@lorvorc.mips.inka.de> <20191205051145.78f9a805.freebsd@edvax.de> <20191205073531.cb2a23ac.freebsd@edvax.de>

next in thread | previous in thread | raw e-mail | index | archive | help
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 ...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?798639b5-75fb-a82f-c024-4eee8d55e1c5>