anordal / shellharden

The corrective bash syntax highlighter
Mozilla Public License 2.0
4.63k stars 130 forks source link

How to dynamically get the contents of a function? Eg; `declare -f $func` #49

Closed tombh closed 2 years ago

tombh commented 2 years ago

I feel like I must be missing something obvious, my apologies if so. I want to do something like this:

function _get_contents_of_function {
  local func=$1
  # shellcheck disable=2086
  declare -f $func # because "$func" doesn't work
}

Have I got the wrong code, or shellharden doesn't support any kind of ignoring? Or is this kind of meta programming just not supported by shellharden?

tombh commented 2 years ago

It was something obvious, my own bug elsewhere in my code! declare -f "$func" does indeed work 🤦‍