(or "In dash, ... is not supported." when using
dash
)
#!/bin/sh
name="PATH"
echo "${!name}"
The easiest solution is to switch to a shell that does support
indirect expansion, like bash
:
#!/bin/bash
name="PATH"
echo "${!name}"
Alternatively, carefully rewrite using eval
:
#!/bin/sh
name=PATH
eval "echo \"\$$name\""
Indirection expansion is an extension in bash
and
ksh
, and not supported in dash
or POSIX
sh
. Either switch to a shell that supports them, or write
around it with careful use of eval
. Take care to validate
the variable name to avoid fragility and code injection.
If you only intend to target shells that supports this feature, you can change the shebang to a shell that guarantees support, or ignore this warning.
You can use # shellcheck disable=SC3000-SC4000
to ignore
all such compatibility warnings.
ShellCheck is a static analysis tool for shell scripts. This page is part of its documentation.