Reputation: 66650
I have code like this:
public function shell($code) {
$code = preg_replace('/"/', '\\"', $code);
exec('bash -c "' . $code . '"', $result);
return $result;
}
and when I call shell("echo $0");
I'm getting sh instead of bash, why?
Upvotes: 1
Views: 136
Reputation: 782508
The original shell is expanding the variable inside doublequotes. To prevent variable expansion, use single quotes:
exec("bash -c '" . $code . "'", $result);
Upvotes: 3