Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • What is the ! exclamation mark printf '%s\n' "${!name}" for? Commented Aug 11, 2015 at 12:24
  • 2
    Its called indirect expansion of bash parameter expansion..read this Commented Aug 11, 2015 at 12:27
  • 2
    Bash also has a nicer alternative to declare / eval: printf -v varname '%fmt' args. Some bash-completion internal functions use this for call-by-reference. (pass the name of a variable to store into). Commented Aug 11, 2015 at 18:25
  • Note: Using declare only sets the variable in the local scope, while the eval approach sets it globally. Commented Jun 27, 2019 at 3:21
  • 2
    @user declare has flag -g to declare variable to be a global. Commented May 11, 2021 at 8:12