On Tuesday 05 November 2002 09:51 am, Chad is done writ: > Is there a way in a bash script to trim the spaces from the front and > end of a variable
> I have a script that contains the following variable definition > BLOCKED_SERVICES="tcp,111,Sun RPC;\ > udp,111,Sun RPC;\ > tcp,443,Microsoft DS;\ > udp,443,Microsoft DS" > I am wondering what the simplest method of extracting each of the three > elements from each line of the variable. In otherwords, each line is a > PROTOCOL, PORT_RANGE, and DESCRIPTION. I have tried a for loop in bash First, you say that you have that as a variable. Why, and then why split it up? If you need it split up, why not just have it as a seperate datafile? Then you could change that, without changing the script, and you could combine, or dice and chop it easily. For example, with a datafile, you could then say export BLOCKED_SERVICES=`cat myblocked` but where you need the services broken out, youi would want to use awk: # start of awk script BEGIN { FS = ","; # define the comma as the field seperator } { print $1, $2, $3; # awk automagicaly splits the line into fields, as # defined by the FS (default is whitespace) } # end of awk script mark -- redhat-list mailing list unsubscribe mailto:redhat-list-request@;redhat.com?subject=unsubscribe https://listman.redhat.com/mailman/listinfo/redhat-list