Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss] Bourne Shell variable assignment question



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.





BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org