-
Notifications
You must be signed in to change notification settings - Fork 1.9k
SC3053
Vidar Holen edited this page Sep 2, 2020
·
2 revisions
(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.
- Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!