bash/ksh/scripting eval subshell quotes
问题 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 回答1: 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 the eval : $ CMD="ls -ltr" $ eval "W=\$( $CMD )" $ echo $W total 197092