1

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...:/

fejese
  • 4,601
  • 4
  • 29
  • 36
aprin
  • 123
  • 1
  • 9

1 Answers1

3

You can make variable variable as suggested here: Bash - variable variables

var="${1}_one"
echo ${!var}
Community
  • 1
  • 1
fejese
  • 4,601
  • 4
  • 29
  • 36