Counter in sh inside loop, value "encapsulation"

Valeri Galtsev galtsev at kicp.uchicago.edu
Thu Dec 5 15:02:01 UTC 2019



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
++++++++++++++++++++++++++++++++++++++++


More information about the freebsd-questions mailing list