From owner-svn-src-head@FreeBSD.ORG Wed Dec 19 21:04:22 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 27780F75; Wed, 19 Dec 2012 21:04:22 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay02.stack.nl [IPv6:2001:610:1108:5010::104]) by mx1.freebsd.org (Postfix) with ESMTP id AAF8B8FC0A; Wed, 19 Dec 2012 21:04:19 +0000 (UTC) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id 0A8E0358C2A; Wed, 19 Dec 2012 22:04:19 +0100 (CET) Received: by snail.stack.nl (Postfix, from userid 1677) id DDFBA2848C; Wed, 19 Dec 2012 22:04:18 +0100 (CET) Date: Wed, 19 Dec 2012 22:04:18 +0100 From: Jilles Tjoelker To: d@delphij.net Subject: Re: svn commit: r244198 - in head: etc/rc.d sbin/sysctl Message-ID: <20121219210418.GA83983@stack.nl> References: <201212132332.qBDNWmK4037503@svn.freebsd.org> <50D1D720.80206@FreeBSD.org> <1355931456.1198.203.camel@revolution.hippie.lan> <05CC5BAD-B968-4A7A-8097-A3344D970D63@mu.org> <1355932607.1198.206.camel@revolution.hippie.lan> <50D2128A.7030205@delphij.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <50D2128A.7030205@delphij.net> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: Ian Lepore , "src-committers@freebsd.org" , "svn-src-all@freebsd.org" , Alfred Perlstein , Xin LI , "svn-src-head@freebsd.org" , Andrey Zonov X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Dec 2012 21:04:22 -0000 On Wed, Dec 19, 2012 at 11:16:26AM -0800, Xin Li wrote: > It may be worthy to make sysctl(8) to accept mutiple -f's, but it > seems to be hard to write shell scripts that utilizes this feature in > a elegant manner. This is possible but indeed a bit ugly. Hard-coding the list of files is not too bad: shift $# for _f in /etc/sysctl.d/* /etc/sysctl.conf /etc/sysctl.conf.local; do [ -r "$_f" ] && set -- "$@" -f "$_f" done sysctl "$@" If the list is passed in the positional parameters it becomes uglier: _first=1 for _f do [ -n "$_first" ] && shift $# _first= [ -r "$_f" ] && set -- "$@" -f "$_f" done sysctl "$@" This uses for's temporary storage of the words being iterated over, building a new set of positional parameters in the loop. An alternative is to append the new list to the old one and to use a saved copy of $# to remove the old elements afterwards. It would be nice to store the arguments in a variable but that is not possible because all characters are valid in pathnames, except the null character which cannot be used in shell either. -- Jilles Tjoelker