简体   繁体   English

通过unix脚本运行php

[英]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 我有些疑惑

  1. What is $0 and what is $@ 什么是$0 ,什么是$@
  2. what is ERR=$? 什么是ERR=$?
  3. what does -- $@ in 5th line do 什么-- $@第5行的-- $@
  4. I wanted to know if can i pass data.php as a parameter. 我想知道我是否可以将data.php作为参数传递。 so that i have only i shell script for all kind of execution . 所以我只有i shell脚本用于所有类型的执行。 Say, i want to run "sh ss.sh data1.php" then this should run data1.php, if run "ss ss.sh data2.php" it should run data2.php – 说,我想运行“sh ss.sh data1.php”然后这应该运行data1.php,如果运行“ss ss.sh data2.php”它应该运行data2.php -

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那么$0start_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.

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