Get enviroment variable from string with ash

Consider the following:

/ # export string="TEMPLATEGO_SERVICE_HOST"
/ # echo $string

With bash I can do:

/ echo ${!string}

If I try the same with ash, I get the following error:

/ # echo ${!string}
ash: syntax error: bad substitution

I am running inside a alpine container and as a workaround I am downloading bash and using it. But want to avoid the extra size on my docker image.


The only way to do this in ash is to use eval. However, you should verify that what you are trying to evaluate consists only of a valid shell identifier to avoid executing unintended code from an untrusted value. For example,

if echo "$string" | grep -q '^[a-zA-Z_][a-zA-Z0-9_]*$' "$string"; then
    eval echo \$$string

Need Your Help

ASP.NET - Extend gridview to allow filtering, sorting, paging, etc

c# .net gridview

I have seen threads on many sites regarding extending the gridview control so obviously this will be a duplicate. But I haven't found any that truly extend the control to the extent that you could ...

Got org.apache.commons.mail.EmailException at using common-mail to send e-mail by Hotmail

java javamail

I uses following code to send e-mail by hotmail service just like the User Guide