[Discuss] Bourne Shell variable assignment question
Richard Pieri
richard.pieri at gmail.com
Thu Dec 15 19:14:03 EST 2011
On Dec 15, 2011, at 4:35 PM, Jerry Feldman wrote:
>
> This is 100% agreed. The issue is that he does not want to source the
> file and I have not been able to talk him out of it. In the past I have
> written scripts where you could read the name of a variable, and then
> convert it to a variable name, but I don't think I've done it in Bourne
> of BASH.
You pretty well have to politely inform this person that he's an idiot. You could do something like this:
for line in `cat file.txt`; do
eval ${line}
done
Which has the "benefit" of roughly duplicating source in slow motion. You can't do it with readline because the assignment fails. bash won't use an environment variable as a variable name, at least not directly:
$ foo=bar
$ ${foo}=baz
bash: bar=baz: command not found
"Prevent malicious code"? It's a shell script. Use the Mk.I Eyeball. Because I can stuff malicious code into an "x=y" statement that matches his egrep without any difficulty at all:
foo="`rm -rf *`"
--Rich P.
More information about the Discuss
mailing list