This shows you the differences between two versions of the page.
programming [2017/08/24 09:24] dlicious Initial page with Python warning configuration |
programming [2018/04/09 11:11] (current) dlicious Added section on indirect variables in POSIX shells |
||
---|---|---|---|
Line 18: | Line 18: | ||
warnings.warn("Something isn't quite right, but we don't have to abort over it.") | warnings.warn("Something isn't quite right, but we don't have to abort over it.") | ||
warnings.warn("Something isn't quite right, but we don't have to abort over it.", UserWarning, stacklevel=1) | warnings.warn("Something isn't quite right, but we don't have to abort over it.", UserWarning, stacklevel=1) | ||
+ | </code> | ||
+ | |||
+ | ====== Indirect variables in shell scripts ====== | ||
+ | |||
+ | Normally, you'd use an associative array for this (including BASH) instead of manually embedding a variable in another variable, but this solution works in POSIX environments like regular Bourne shell (and BASH's emulation of it): | ||
+ | |||
+ | <code bash> | ||
+ | favorite_color_joe=gold | ||
+ | favorite_color_jane=blue | ||
+ | |||
+ | person=${1} | ||
+ | |||
+ | target_interface=`eval echo \$favorite_color_${person}` | ||
</code> | </code> |