I’m using ksh and having some trouble. Why does this code not run?
[root]$ CMD="ls -ltr"
[root]$ eval "W=$( $CMD )"
[root]$ ksh: ls -ltr: not found.
[root]$ echo $W
But this works fine:
[root]$ CMD="ls -ltr"
[root]$ eval 'W=$('$CMD')'
[root]$ echo $W
You need to escape the
$(...)with a backslash to prevent it from being evaluated by the outside shell. The$(...)needs be preserved as is until it is handed off to theeval: