Chaminda
Chaminda

Reputation: 78

Shell parameter substitution with sh

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 ?

Upvotes: 0

Views: 1796

Answers (1)

Barmar
Barmar

Reputation: 782105

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}\""

Upvotes: 3

Related Questions