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
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to