Add a linecount shell function, and use it to count the lines in the

output from MAKEDEV.local.

Fixes PR 37498 from dlagner at rambler.ru, using an idea from David
Laight.  The while loop in the old code is executed in a subshell, so it
can't make persistent modifications to the parent shell's variables.
This commit is contained in:
apb 2007-12-08 17:31:12 +00:00
parent 1e1bd31956
commit 3bc3600ea3

View File

@ -1,5 +1,5 @@
#!/bin/sh -
# $NetBSD: MAKEDEV.tmpl,v 1.91 2007/11/20 18:58:46 pooka Exp $
# $NetBSD: MAKEDEV.tmpl,v 1.92 2007/12/08 17:31:12 apb Exp $
#
# Copyright (c) 2003,2007 The NetBSD Foundation, Inc.
# All rights reserved.
@ -346,6 +346,17 @@ hexprint()
echo "${hex:-0}"
}
# linecount multiline_string
# count the number of lines in the string
#
linecount()
{
local IFS='
' # just a newline, no other white space between the quotes
set -- $1
echo $#
}
setup()
{
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/rescue
@ -1708,10 +1719,8 @@ local)
if [ -f "$0.local" ]; then
umask 0
if [ -n "$count_nodes" ]; then
sh "$0.local" $opts -s all | \
while read l; do
count_nodes=$((count_nodes + 1))
done
count_nodes=$((count_nodes + \
$(linecount "$(sh "$0.local" $opts -s all)") ))
else
sh "$0.local" $opts all
fi