shell variable interpolation?
Steven Hanley
sjh at svana.org
Mon Nov 18 11:48:27 EST 2002
All
Okay so I am wondering if there is a better way to interpolate variables
within a string in shell than I have worked out here.
(seeing how we have some sick disturbed individuals who do things with sh
that it was probably never meant to do (hi Michael) I thought I might ask.
I have
====
#! /bin/sh
multi_apply () {
local string=$1
local list=$2
for item in $list ; do
line=`eval echo "$string"` echo $line
done
}
a1="one long \$item argument"
a2="and another one"
multi_apply "$a1" "$a2"
====
which when I run it outputs
one long and argument
one long another argument
one long one argument
the idea is to pass in and a string in which the items should be inserted.
This seems to work fine, I wonder however if there is a better/more
efficient/faster than this.
Ideas/Suggestions?
See You
Steve
--
sjh at wibble.net http://wibble.net/~sjh
You are subtle as a window pane standing in my view
but I will wait for it to rain so that I can see you
Anticipate - Ani
More information about the linux
mailing list