算术shell_exec()返回0 php

算术shell_exec()返回0 php,php,math,return,shell-exec,Php,Math,Return,Shell Exec,我有这样的数据 field1,field2 test,11 test,3 test,14 test,200 test,8 我想对所有的字段2求和。我使用shell_exec $execute = 'x=0;for i in `cut -d\',\' -f2 /app/tibs/tosweb/CCS1/tos/temp/test2.txt`; do let x+=i; echo $x; done'; $output = shell_exec($execute); echo "<pre>

我有这样的数据

field1,field2
test,11
test,3
test,14
test,200
test,8
我想对所有的字段2求和。我使用shell_exec

$execute = 'x=0;for i in `cut -d\',\' -f2 /app/tibs/tosweb/CCS1/tos/temp/test2.txt`; do let x+=i; echo $x; done';
$output = shell_exec($execute);
echo "<pre>".var_export($output, TRUE)."</pre>\\n";
$execute='x=0;对于'cut-d\'中的i,\'-f2/app/tibs/tosweb/CCS1/tos/temp/test2.txt`;让x+=i;echo$x;完成';
$output=shell_exec($execute);
echo”“.var\u导出($output,TRUE)。“\\n”;
我不明白,为什么x的值总是返回0? 请帮助我的朋友,谢谢你之前


*抱歉,我的英语不好:p

cut
不接受多字符分隔符(由于转义,它将转义分隔符视为多字符分隔符)。因此,您可以使用unescaped:

x=0;for i in `awk -F\',\' '{ print $1 }'  data.txt `; do let x+=i; echo $x; done
或者改为
awk

$execute = "x=0;for i in `cut -d',' -f2 /app/tibs/tosweb/CCS1/tos/temp/test2.txt`; do let x+=i; echo $x; done";
要防止转义,请使用双qoutes括起命令:


在使用引号之前,我使用了双引号。如果我使用双引号,返回值总是字符串(0)。我在其他服务器上尝试代码,它工作正常。我在我的服务器中尝试了这一点:shell_exec(“echo$((10+5))”;并且返回值为空。为什么我用算术运算不行?我在我的代码上试过了,效果很好。您能够从SSH cli运行该命令吗?
$execute = "x=0;for i in `cut -d',' -f2 /app/tibs/tosweb/CCS1/tos/temp/test2.txt`; do let x+=i; echo $x; done";