0

I wanted to construct a variable name as shown below at run time, how can do it in bash shell scripting.

concatenate_eror_file_user_${instance_name}=echo ${File_User},${concatenate_eror_file_user_${instance_name}}

Above line gives me an error as ${File_User},${concatenate_eror_file_user_${instance_name}}: bad substitution here instance_name=INST

File_User=test

As instance_name and File_USer values will be changed in my scripts i am in need of the above mentioned.

teepu
  • 266
  • 1
  • 6
  • 18
  • Several errors: First, because of the space after the `echo`, you would assign only the word `echo` to your variable and run the rest of the line as a command. Second, the nesting of the substitiution `${concatenate_eror_file_user_${instance_name}}` is syntactically incorrect. I don't know what you want to achieve; maybe you want `concatenate_eror_file_user` be an associative array and use `$instance_name` as a key? – user1934428 Mar 02 '20 at 12:22
  • Please [edit] your question and make clear what you want to achieve. I understand that you have variables `instance_name` and `File_User`. Show example input for both variable,. e.g. `instanceName=TheInstanceName` and `File_User=test`, and expected output matching the example input. What is the resulting variable name you want to construct and what is the expected value of the variable? – Bodo Mar 02 '20 at 12:38
  • You are basically assigning recursively. You can't say "`x=bob,$x`" and expect anything but a *previous* value to be included. – Paul Hodges Mar 02 '20 at 14:13
  • when i run the line i will have `concatenate_eror_file_user_INST=test,values of concatenate_eror_file_user_INST` also as i am concatenating `concatenate_eror_file_user_INST` and it will have NULL value hence `concatenate_eror_file_user_INST=test,` is what i expect – teepu Mar 02 '20 at 14:21
  • 1
    Does this answer your question? [Creating a string variable name from the value of another string](https://stackoverflow.com/questions/13716607/creating-a-string-variable-name-from-the-value-of-another-string) – pjh Mar 02 '20 at 14:26

0 Answers0