> -----Original Message----- > From: mark > Subject: Re: Bash Script Question > > > 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
Or (based on your requirements) you can define a database using shell arrays #!/bin/bash PROTO=1 ; PORT=2 ; DESC=3 declare -a BLOCKED_SERVICE=( [0]="tcp,111,'Sun RPC'" [1]="udp,111,'Sun RPC'" [2]="tcp,443,'Microsoft DS'" [3]="udp,443,'Microsoft DS'") IFS=':' for SUB_SCRIPT in ${BLOCKED_SERVICE[*]} ; do IFS=',' ; let i=1 for VAL in ${SUB_SCRIPT} ; do SUBVAL[$i]=${VAL} ; let i++ done echo "Proto=${SUBVAL[$PROTO]} Port=${SUBVAL[$PORT]} Desc=${SUBVAL[$DESC]}" done -- redhat-list mailing list unsubscribe mailto:redhat-list-request@;redhat.com?subject=unsubscribe https://listman.redhat.com/mailman/listinfo/redhat-list