简体   繁体   English

php循环的结果未传递给shell脚本

[英]result of php loop not passing to shell script

I have a small foreach loop in php but the results will not pass to a shell script. 我在php中有一个小的foreach循环,但结果不会传递给Shell脚本。 see below: 见下文:

$contents = file("$target_dir/$user.temp.txt");

foreach($contents as $line) {
    echo $line . "<br />";
    exec("sh read.sh $line >> tempfile");
}

the echo statement works just fine and displays the data to screen as it should. echo语句工作得很好,并按需要在屏幕上显示数据。 however the result of $line does not make it to the shell script, but when I replace $line with a random string it does. 但是,$ line的结果不会进入shell脚本,但是当我将$ line替换为随机字符串时,它会返回。 here is the shell script: 这是shell脚本:

#!/bin/bash
#test script
echo "test output: $1"

when trying to call the shell script with $line in place, the tempfile will get created but is blank. 尝试使用$ line调用shell脚本时,将创建临时文件,但该文件为空。 all my permissions are set to 777 and the group calling the script is the same owner as the folder. 我所有的权限都设置为777,并且调用该脚本的组与该文件夹是同一所有者。 I've reviewed other posts about php loops but dont seem to find anything that matches exactly what my issue is. 我已经查看了有关php循环的其他文章,但似乎找不到与我的问题完全匹配的内容。

Thanks in advance for any insight. 预先感谢您的任何见解。

需要在$line添加单引号。

exec("sh read.sh '$line' >> tempfile");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM