Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running php via a unix script

Tags:

linux

shell

php

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

  1. What is $0 and what is $@
  2. what is ERR=$?
  3. what does -- $@ in 5th line do
  4. I wanted to know if can i pass data.php as a parameter. so that i have only i shell script for all kind of execution . 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 –
like image 407
aWebDeveloper Avatar asked Aug 09 '26 00:08

aWebDeveloper


1 Answers

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 -- $@
like image 87
dwalter Avatar answered Aug 10 '26 13:08

dwalter