hints on shell string expansion ?

David Schultz das at FreeBSD.ORG
Mon Jul 7 01:34:26 PDT 2003


On Mon, Jul 07, 2003, Luigi Rizzo wrote:
> but i because the string of actions is used in several places,
> I would love to find a way to group actions into a single
> variable and then write something like this
> 
> 	actions="allow 'deny log' 'pipe 10'"
> 	for act in $actions ; do
> 		echo "add $act ip from 1.2.3.4 to 5.6.7.8"
> 	done

I've used a trick with 'set' for something similar, so perhaps
this will work for you:

	set -- allow 'deny log' 'pipe 10'
	while [ $# -gt 0 ]; do
		act=$1
		# do stuff here
		shift
	done

You can also use 'eval', but that makes escaping nasty.  It may be
possible to change the IFS to something other than space, but I've
never messed around with that particular black magic.


More information about the freebsd-hackers mailing list