如何调用从shell脚本文件PHP文件 [英] How to call PHP file from a shell script file
本文介绍了如何调用从shell脚本文件PHP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道shell脚本的想法。我需要有一个循环的shell脚本。在每个循环需要调用一些参数的PHP文件。有没有办法做到这一点?
I have no idea about shell scripting . I need a shell script which has a loop . In each loop it needs to call a PHP file with some parameters . Is there any way to do it ??
推荐答案
在你的PHP文件名为test.php的,例如:
In your php file named test.php, for example
<?php
//like programs in c language, use $argc, $argv access command line argument number and arguments, uncomment below two line to dump $argc and $argv
//var_dump($argc); //an integer
//var_dump($argv); //an array with arguments
//use args and do anything you want
echo "do my job\n";
exit(0);
然后创建一个shell脚本命名test.sh
then create a shell script named test.sh
#! `which bash`
php=`which php`
i=10
while [[ $i -ge 0 ]];
do
$php test.php 1 2
((i--))
done
把两个文件在同一目录下。然后在终端中运行命令
bash test.sh
这篇关于如何调用从shell脚本文件PHP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文