Greetins, I need to do the following:
string_a="string_a${int}"
string_b="string_b${int}"
int=1
String variables are in a text file, other than file which contains bash script and where variable int is declared. I need that I write string_a${int} in a text file, and sed that line from this file so that it becomes a string variable with nested int variable ${int}. Do you know any nice solution for that? :)
Maybe I try to write codes in both files:
File "string"
aaaaaaaaa${i}
File "program"
#!/bin/bash
int=1
i=1
string=$(sed -n "${int}p" string)
echo ${string}
As you can see, I try to sed first line from file "string", but as a result I get aaaaaaaaa${i} instead of aaaaaaaaa1.
String variables are in a text file, other than variable int.Can you clarify it.echo ${!string_a}?foo=barandbar=5,$fooproduces "bar", while${!foo}produces 5. The exclamation tellsbashto use the value offooas the name of the parameter to expand using$. It's called indirect parameter expansion.