[英]Running php via a unix script
I have the above shell script . 我有上面的shell脚本。
#!/bin/bash
# a shell script that keeps looping until an exit code is given
nice php -q -f ./data.php -- $@
ERR=$?
exec $0 $@
I have a few doubts 我有些疑惑
$0
and what is $@
什么是$0
,什么是$@
ERR=$?
什么是ERR=$?
-- $@
in 5th line do 什么-- $@
第5行的-- $@
1) $0
is the name of the executable (the script in your case, eg: if your script is called start_me
then $0
is start_me
) 1) $0
是可执行文件的名称(在您的情况下是脚本,例如:如果您的脚本名为start_me
那么$0
是start_me
)
2) ERR=$?
2) ERR=$?
gets the return code of nice php -q -f ./data.php -- $@
获取nice php -q -f ./data.php -- $@
的返回码nice php -q -f ./data.php -- $@
3) -- $@
does two things, first of all it tell the php
command that all following parameter shall be passed to data.php
and $@
passes all given parameter to the script to ./data.php
(eg. ./your_script_name foo bar
will translate to nice php -q -f ./data.php -- foo bar
) 3) -- $@
做了两件事,首先它告诉php
命令将所有后续参数传递给data.php
并且$@
将所有给定参数传递给脚本到./data.php
(例如./your_script_name foo bar
将转换为nice php -q -f ./data.php -- foo bar
)
4) short answer yes, but you have to change the script to 4)简短回答是,但你必须将脚本更改为
YOUR_FILE=$1
shift #this removes the first argument from $@
nice php -q -f ./$YOUR_FILE -- $@
$0
is the name of the script. 是脚本的名称。
$@
are the arguments given to the script 是给脚本的参数
ERR=$?
catches the status code of the previous command 捕获上一个命令的状态代码
php_command="php -q -f $1"
shift
nice $php_command -- $@
You take the first parameter for the f-flag, then you shift it off the parameter list and pass the rest after the double dashes. 您获取f标志的第一个参数,然后将其从参数列表中移开并在双破折号后传递其余参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.