3

我有上面的 shell 脚本。

#!/bin/bash

# a shell script that keeps looping until an exit code is given

nice php -q -f ./data.php -- $@
ERR=$?

exec $0 $@

我有几个疑问

  1. 什么是$0什么$@
  2. 什么是ERR=$?
  3. -- $@第 5 行做什么
  4. 我想知道是否可以将 data.php 作为参数传递。所以我只有我所有类型的执行的 shell 脚本。说,我想运行“sh ss.sh data1.php”那么这应该运行data1.php,如果运行“ss ss.sh data2.php”它应该运行data2.php -</li>
4

2 回答 2

1

1)$0是可执行文件的名称(在您的情况下是脚本,例如:如果您的脚本被调用,start_me则为)$0start_me

2)ERR=$?获取返回码nice php -q -f ./data.php -- $@

3)-- $@做两件事,首先它告诉php命令所有后续参数都应传递给data.php并将$@所有给定参数传递给脚本./data.php(例如./your_script_name foo bar将转换为nice php -q -f ./data.php -- foo bar

4)简短的回答是的,但是您必须将脚本更改为

 YOUR_FILE=$1
 shift #this removes the first argument from $@
 nice php -q -f ./$YOUR_FILE -- $@
于 2012-05-02T14:16:47.057 回答
0
$0 

是脚本的名称。

$@ 

是给脚本的参数

ERR=$? 

捕获上一条命令的状态码

php_command="php -q -f $1"
shift
nice $php_command -- $@

您获取 f 标志的第一个参数,然后将其从参数列表中移出,并在双破折号后传递其余参数。

于 2012-05-02T14:13:23.230 回答