PHP exec command is not working with awk command [

2019-09-22 13:54发布

问题:

I have following code:

$eff=40;
$pos=34;

$line=exec("tail $i.dssp -n $eff | awk -F" " -v var=$pos '{if ($2==var) print FNR}'");

Please help...

回答1:

As I said in my answer to your previous question, you can fix this easily by using single quotes on the inside.

PHP Code

<?php
$eff=40;
$pos=34;
$i = 'hello';
$line=exec("tail $i.dssp -n $eff | awk -F' ' -v var=$pos '{if ($2==var) print FNR}'");
print "$line\n";
?>

Sample Input (hello.dssp):

foobar 34

Sample Output:

1


标签: php awk exec