hugme: (Default)
[personal profile] hugme
someone sent me this script:

#!/bin/bash

COMPUTERS="$SQLSERVICES $MAILSERVICES $PHONESERVICES"
SQLSERVICES="80 8080"
MAILSERVICES="110 25 143"
PHONESERVICES="53 4569 5036 5060"

        for x in ${COMPUTERS}; do
	  echo ${x}   #Should echo the current service list
	  for y in ${x}; do
	    echo ${y}  #Should echo the ports in $x
	  done
        done


saying that it doesn't work... well, no, it doesn't... What is being done isn't an easy thing, shell pointers are a pain.. this is how it should be written

#!/bin/bash

SQLSERVICES="80 8080"
MAILSERVICES="110 25 143"
PHONESERVICES="53 4569 5036 5060"
COMPUTERS="SQLSERVICES MAILSERVICES PHONESERVICES"

for x in ${COMPUTERS}; do
        echo ${x}   #Should echo the current service list
        for y in ${x}; do
                POINTER="echo \$"$y
                eval $POINTER  #Should echo the ports in $x
        done
done

I don't think this is what he wants but it matches what he listed in the one he sent me...

this is what I think he wants:

#!/bin/bash

SQLSERVICES="80 8080"
MAILSERVICES="110 25 143"
PHONESERVICES="53 4569 5036 5060"
COMPUTERS="SQLSERVICES MAILSERVICES PHONESERVICES"

for x in ${COMPUTERS}; do
        POINTER="echo \$"$x
        for y in `eval $POINTER`; do
                echo ${x} ${y}   #Should echo the current service list
        done
done

looks a little bit simpler, prints out the name and the service on each line... we will see...

comments?

Profile

hugme: (Default)
hugme

April 2011

S M T W T F S
     12
3456789
10111213141516
17 181920212223
24252627282930

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Apr. 8th, 2026 02:36 am
Powered by Dreamwidth Studios