Artificial intelligent assistant

How to dynamically look up shell variable name I have this situation: zmx_stderr='\033[1;35m' zmx_stdout='\033[1;36m' tag='foobar' tailing(){ echo "tailing logs for ${tag} ..."; while read line; do echo -e "$zmx_${1} $tag $1${zmx_no_color}: $line" done; } someone calls tailing() with: tailing stderr tailing stdout how can I look up the zmx_stdout and zmx_stderr dynamically? This doesn't work: $zmx_${1} I just get this: stdout foobar stdout: but I am looking for: foobar stdout: with control chars being generated. * * *

You could use a helper variable to build the name of the target variable and then use variable indirection:


zmx_var=zmx_$1
echo -e "${!zmx_var} $tag $1${zmx_no_color}: $line"

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 56e1c2e2be7ff9c8adc6bd0615fed187