Perl and PHP do this with backticks. For example,
$output = `ls`;
Returns a directory listing. A similar function, system(\"foo\")
system(\"foo\")
In shell
OUTPUT=`ls`
or alternatively
OUTPUT=$(ls)
This second method is better because it allows nesting, but isn't supported by all shells, unlike the first method.