-2

I have argument in my script called attach_sub which take 2 argument

 attach_sub (host_id, vdc_sub_id)

I need to provide attach_sub function a second argument which is the value of

prm_vdc_id variable

let say

prm_vdc_id = 5

I got a variable called vdc_sub_id which should be yielding the value of prm_vdc_id

vdc_sub = 'prm'
vdc_sub_id = vdc_sub+'_vdc_id'
'prm_vdc_id'

but I am getting vdc_sub_id value as a string and not the actual

value of prm_vdc_id to be assign to the function

in short I want the function to take vdc_sub_id as its second argument

with a value of 5 in this case

attach_sub (host_id, vdc_sub_id)

any help will be appreciated

user8788348
  • 15
  • 1
  • 4
  • Possible duplicate of [How do I create a variable number of variables?](https://stackoverflow.com/questions/1373164/how-do-i-create-a-variable-number-of-variables) - or variations thereof – wwii Nov 26 '17 at 17:57

2 Answers2

0

Use exec(vdc_sub_+"_vcd_id"), but you probably shouldn't code this way.

mcchucklezz
  • 376
  • 1
  • 16
-1

You're probably doing something wrong here, but the reason why you're getting a string is because you're adding the two strings. If you want the variable which corresponds to the string value, do:

eval(vdc_sub_+"_vcd_id")

A better way of going about this would be to us a dictionary of sub_ids, where any possible value of vdc_sub corresponds to a xxx_vdc_id:

sub_ids = {'prm': 5}

Now, the equivalent of xxx_vdc_id would be sub_ids[xxx].

Sebastian Mendez
  • 2,859
  • 14
  • 25