I am trying to create a script that checks for command line parameters passed to the script.
If there are no parameters passed then the script should exit with the error code 1 and print the message.
If the script was passed with only one command line parameter then I need to check that the parameter was to a valid php script. If the parameter passed was to any one of the three valid scripts then the php script is executed with any and all command line parameters also passed to the bash script.
Given the following bash script command:
myscript.sh /home/scripts/email.php --IgnoreOptin="True" --AccountNumber="987456321"
The script should evaluate and then output this:
php /home/scripts/email.php --IgnoreOptin="True" --AccountNumber="987456321"
I would need to be able to handle any quoted command line input to the shell script in the execution of the php command.
Here is my code I am starting with:
if [ $# -eq 0 ];
echo "No script name entered"
echo "Enter full path to script and any command line parameters"
if ["$1" -eq "/home/scripts/compute.php" -o
"$1" -eq "/home/scripts/deactivate.php" -o
"$1" -eq "/home/scripts/email.php"];
echo "No valid script name entered"
I cannot get past the second if statement's check for whether the command line input entered was equal to one of the enumerated php scripts in the bash script.
Here is my script output error:
./myscript.sh: line 8: [/home/scripts/compute.php: No such file or directory
./myscript.sh: line 9: /home/scripts/deactivate.php: Permission denied
./myscript.sh: line 10:/home/scripts/email.php: Permission denied
Not a valid script
Any help with this would be greatly appreciated.