Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Dec 2012 13:10:06 -0800
From:      Garrett Cooper <yanegomi@gmail.com>
To:        Jilles Tjoelker <jilles@stack.nl>
Cc:        Ian Lepore <freebsd@damnhippie.dyndns.org>, "src-committers@freebsd.org" <src-committers@freebsd.org>, d@delphij.net, "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>, Alfred Perlstein <bright@mu.org>, Xin LI <delphij@freebsd.org>, "svn-src-head@freebsd.org" <svn-src-head@freebsd.org>, Andrey Zonov <zont@freebsd.org>
Subject:   Re: svn commit: r244198 - in head: etc/rc.d sbin/sysctl
Message-ID:  <CAGH67wRTdBCZLq1R8-yqD6EBZ%2B=F228-0o_8TvU3b0KZD6vUfg@mail.gmail.com>
In-Reply-To: <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> <F158CD10-B65B-4BBA-BCAD-6A52BC5C8FDF@mu.org> <50D2128A.7030205@delphij.net> <20121219210418.GA83983@stack.nl>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Dec 19, 2012 at 1:04 PM, Jilles Tjoelker <jilles@stack.nl> wrote:
> 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.

    find -exec / echo | xargs ? Seems like there's a better way to solve this.
Thanks,
-Garrett



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAGH67wRTdBCZLq1R8-yqD6EBZ%2B=F228-0o_8TvU3b0KZD6vUfg>