Assuming we've all read https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html (specifically, search for indirect expansion).
The question means, instead of doing:
alpha_date=1563980822; alpha_hash=bfc1a9ad; alpha_url=http://example.com/bfc1a9ad; alpha_path=/build/alpha; alpha_status=failure; bravo_date=1563981822; bravo_hash=f76025c5; bravo_url=http://example.com/f76025c5; bravo_path=/build/alpha2; bravo_status=success; charlie_date=1563982822; charlie_hash=289f55fd; charlie_url=http://example.com/289f55fd; charlie_path=/build/charlie; charlie_status=success
for prefix in alpha bravo charlie; do
for suffix in date hash url path status; do
tempvar="${prefix}_${suffix}"
echo -n "$tempvar: ${!tempvar}"$'\t'
done
echo
done
This works and outputs:
alpha_date: 1563980822 alpha_hash: bfc1a9ad alpha_url: http://example.com/bfc1a9ad alpha_path: /build/alpha alpha_status: failure
bravo_date: 1563981822 bravo_hash: f76025c5 bravo_url: http://example.com/f76025c5 bravo_path: /build/alpha2 bravo_status: success
charlie_date: 1563982822 charlie_hash: 289f55fd charlie_url: http://example.com/289f55fd charlie_path: /build/charlie charlie_status: success
I'd like to skip creating the tempvar
something like this:
for prefix in alpha bravo charlie; do
for suffix in date hash url path status; do
echo -n "${prefix}_${suffix} is ${!${prefix}_${suffix}}"$'\t'
done
echo
done
But of course I get a bad substitution
error from bash.
Is there any way to do bash "indirect expansion" on a "string"?