Search code examples
fish

Indirect Variable References in fish-shell


How can I do indirect variable references in fish script?

So I have a variable $var1 which contains the name of another variable $var2. No I want to now what is inside $var2.

In bash I could use value = ${!var1} in other shells the quite ugly eval "value=\"\${$var1}\"" is unfortunately needed. But I somehow can't get to work anything in fish.

P.S. I need that because I source files which are defining commands which are given to a script.


Solution

  • Just $$var1.

    Keep in mind that slices are used inside-out, so $$var1[1] is all elements of the variable named by the first element of var1.