Indirect variable setting in bash can be done like so:
#!/bin/bash
foo=bar
ind=foo
echo ${!ind} # prints `bar'
Trying to run the same as a (GNU) Makefile recipe
# Makefile
test:
foo=bar
ind=foo
echo $$\{!ind\}
echo $${!ind}
both with and without escaping the {}
characters fails with the following message:
foo=bar
ind=foo
echo $\{!ind\}
${!ind}
echo ${!ind}
/bin/sh: 1: Bad substitution
/tmp/Makefile:2: recipe for target 'test' failed
make: *** [test] Error 2
The problem is probably some missing/wrong escaping of Makefile's special characters.
Or it could be the order/timing of variable expansion, see make's secondary expansion.
Any ideas?
If it matters, this is bash 4.4.12(1)-release
and make GNU Make 4.1