home | list info | list archive | date index | thread index

[OCLUG-Tech] bash question

A friend of mine recently called me up with an interesting bash question.

As far as I understood, he wants to create variable names dynamically -
he wants to pull this_is_a_variable and "this is a string" from a file
and set this_is_a_variable="this is a string".  He doesn't want to use
arrays, which seem to be the logical solution for flexible variable
stuff.

In messing around with various methods of setting variables, we
discovered an interesting side-effect of using (( )) to set the
variable name:

#!/bin/bash

x=y

echo $y #returns empty/undeclared

(( $x=0 ))

echo $y #returns 0!

exit

Can anyone give a better explaination as to why this works other than my
"inside a mathmatical expression, bash just dumps variable values and
then works the expression: it doesn't treat = any differently from any
other mathmatical operator"?  And, is there a way to do this without
the math (with strings)?

--

Jeremy John Wakeman
jeremywakeman [ at ] istop [ dot ] com
www.polarhome.com/~cael
linux registered user #125171

Attachment: signature.asc
Description: Digital signature

replies