Counter in sh inside loop, value "encapsulation"
Arthur Chance
freebsd at qeng-ho.org
Thu Dec 5 11:03:33 UTC 2019
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 ...
More information about the freebsd-questions
mailing list