svn commit: r244198 - in head: etc/rc.d sbin/sysctl

Garrett Cooper yanegomi at gmail.com
Wed Dec 19 21:10:15 UTC 2012


On Wed, Dec 19, 2012 at 1:04 PM, Jilles Tjoelker <jilles at 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


More information about the svn-src-all mailing list