Reputation: 38332
I have the above shell script .
#!/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 $@
ERR=$?
-- $@
in 5th line do Upvotes: 3
Views: 184
Reputation: 4689
$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.
Upvotes: 0
Reputation: 7468
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
)
2) ERR=$?
gets the return code of 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
)
4) short answer yes, but you have to change the script to
YOUR_FILE=$1
shift #this removes the first argument from $@
nice php -q -f ./$YOUR_FILE -- $@
Upvotes: 1