In bash following command works where it use parameter substitution
$ VALUE_AUS=20m; COUNTRY=AUS; PARAM=VALUE_$COUNTRY; echo ${!PARAM}
20m
However in Alpine container with sh the same command fails
# VALUE_AUS=20m; COUNTRY=AUS; PARAM=VALUE_$COUNTRY; echo ${!PARAM}
/bin/sh: syntax error: bad substitution
What would be the correct syntax to achieve same outcome using /bin/sh?
Indirect variables is a bash
extension.
If Alpine can't run bash
, you'll need to use eval
to emulate this.
# VALUE_AUS=20m; COUNTRY=AUS; PARAM=VALUE_$COUNTRY; eval "echo \"\$${PARAM}\""
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.