我有一个PHP脚本,通过使用反引号操作符在Bash中执行命令从文件中检索200行。下面的代码是什么样子:PHP:反驳无法使用命令
$endline = `(shell execution that returns a number here)`;
$line = $endline - "200";
$lines = "sed -n '".$line.", ".$endline." p' log.txt";
echo $lines;
$file = `$lines`;
echo $file;
此代码返回$lines
为sed -n '1800, 2000 p' log.txt
,但$file
不返回任何结果。当在Bash终端直接使用sed -n '1800, 2000 p' log.txt
时,我会得到预期的结果。
在这里做了什么不正确? '
角色必须逃脱吗?
编辑: shell脚本在数字后面加了一个空格,因此误读了它。
你没有执行命令 – 2012-08-05 20:51:36
尝试'$ file = system($ lines)' – favoretti 2012-08-05 20:55:39
@ColeJohnson反引号不会被视为执行命令吗? – hexacyanide 2012-08-05 21:01:46