Shell envvar question
Hello, I'm looking for shell advice. (Hopefully I got the right forum)
I have a block of code we put into many scripts, and it gets a list of hosts to execute commands against. For readability purposes I'd like the two envvars the scripts uses to be at the front and one within the other. But the 2nd variable isn't resolved yet. I'd like the shell to handle it for me, but I don't have the syntax right. Is there a way to code this?
This doesn't work:
matchTag='test_x86'
command='/opt/local/bin/dosomething.sh $theHost'
#
hostFile='/opt/local/bin/linux/@Linux_hosts.txt'
calling_script=`basename $0` ;
grep $matchTag $hostFile | grep -v '#' | cut -f 1 -d : > /tmp/$calling_script.txt
while read -u 3 theHost ; do $command ; done 3< /tmp/$calling_script.txt
I could do this, but it's not as maintenance friendly.
matchTag='test_x86'
command='/opt/local/bin/dosomething.sh'
#
hostFile='/opt/local/bin/linux/@Linux_hosts.txt'
calling_script=`basename $0` ;
grep $matchTag $hostFile | grep -v '#' | cut -f 1 -d : > /tmp/$calling_script.txt
while read -u 3 theHost ; do $command $theHost; done 3< /tmp/$calling_script.txt
Sometimes I'll want the dynamically retrieved $theHost at the end of $command, sometimes in the middle of $command, etc. So if I could code the not yet resolved envvar into $command and have the shell handle it at runtime, it would be ideal.
Any ideas? Can I put some quotes, double quotes, brackets, curlies or some other special character around things and get the shell to do my work?
Thanks!
Jon
|