Skip to main content

Posts

Showing posts from January, 2016

how to create dynamic variable in unix ?

This is a problem where in you a have a config file and you have wrapper script and a child script where in your wrapper and child script are generic enough to process certain task depending on the parameter you pass to create your dynamic variable and source your static value from a config file, this way you wouldn't need to touch your scripts but only the config. I found a lot of ways through googling easiest would be the bash solution but fortunately i am using ksh so another one was the use of eval, however most of the solutions i found using eval on the net didn't work for me, either i didn't know how to use or apply it, so i tried a few combinations and below is what worked for me : If your doing it in bash shell its quite easy : dev_config_var=abc;  dynamic_value=dev;  dynamic_var=${dynamic_value}_config_var;   echo ${!dynamic_var} so you see the trick if you are in bash is just "!". but if we are doing in ksh, then its a different story.