What is wrong with this indirect command when run with eval ?
#!/bin/bash OS=AIX host=myhost CMD_AIX="(o=\`host \"$host\" \`)" CMD=\$CMD_$OS echo $CMD eval echo $CMD eval "$CMD"
$ myscript.sh $CMD_AIX (o=`host "myhost" `) myscript.sh: line 12: (o=`host: command not found
EDIT - NOTES: It's in a very heterogeneous structure with about 40 servers, mixing SCO, AIX and Linux, several versions of each, including variations of 32 and 64 bits. SCO and AIX cannot be updated. Bash and Korn shell are common in all servers but I'm limited to version 3 of bash (in SCO), Ksh has several differences between them, so we're preferring bash, which haven't support to associative arrays in v3 (it cannot be updated and it's outside of my decisions, and these servers will begin to be replaced by AIX 7 and Linux in a few months).
There are a big system to be maintained which includes some scripts already based in sh and bsh, we won't and cannot reconstruct it now, just tittle maintenance to resist some months until the end of replacement.
The approach used in these scripts is largely spread in a big solution which generates some scripts, which we cannot change it from scratch.
The sample code above is just an adopted snippet, it isn't the real code. Please don't consider the logic, just the problem of indirection (eval).
SOLUTION: I got a solution that worked very fine just chaining the eval, like:
torun=`eval $CMD` output=`eval torun`