Reputation: 123
I need to manipulate arguments given to a function, to make it more compact.
e.g.
hoax_one=1
hoax_boo=5
get_sum(){
echo $1
echo $2
}
..but instead of giving: get_sum "$hoax_one" "$hoax_boo", to give just get_sum hoax.
I was thinking of something like that:
get_sum(){
echo $1_one
echo $2_boo
}
but it outputs
hoax_one
hoax_boo
and not its values (declared before)!
Is it possible? There is a big database with hoax prefixes (and other ones), i need to just run the get_sum with a single word...:/
Upvotes: 1
Views: 184
Reputation: 4628
You can make variable variable as suggested here: Bash - variable variables
var="${1}_one"
echo ${!var}
Upvotes: 3