bash character substitution? Need help

William Park opengeometry-FFYn/CNdgSA at public.gmane.org
Fri Feb 6 20:15:34 UTC 2004


> I have the variable:
> 
> # Enter as (MAC address)>Port(-range),Port(-range),..,Port(-range)
> TRUSTED_IB_TCP=00:11:22:33:44:55>21,53,80-85
> 
>    Now I want to check and see if ports are defined. If not, allow all
> ports from the given MAC address. If so, read out the ports one after
> another in a 'for/while' style loop splitting on the ','. Then inside
> each of those, split on '-' and check to see if there is a value after
> the '-'.
> 
>    The problem is, I know how to split on the ',' (IFS=',' ...) but this
> doesn't seem like it is going to help me because I want to run a
> 'for/while' loop for each value, not assign new variables based on the
> split (like I have done so far). Is there some way to substitute the ','
> with ' ' and then do a 'for/while' loop?
> 
>    I am Googling now but I am having trouble finding the answer. I am
> hoping someone here might be able to point me in the right direction.
> Thanks!

Hint:
    read mac ports <<< "${TRUSTED_IB_TCP/>/ }"
    for p in ${ports//,/ }; do
	case $p in
	    *-?*) echo $p is 'x-y' ;;
	    *-) echo $p is 'x-' ;;
	    *) echo $p is 'x' ;;
	esac
    done

-- 
William Park, Open Geometry Consulting, <opengeometry-FFYn/CNdgSA at public.gmane.org>
Linux solution for data management and processing. 
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list