The problem here is that you are quoting the entiore command you are trying to run as a single variable. As a result, you're not running php
with foo.php
as an argument but instead are attempting to execute a file called php foo.php
. Here's a simpler example to show you what I mean:
$ var1="echo "
$ var2="foo"
$ set -x ## debugging info
$ "$var1$var2"
+ 'echo foo' ### The shell tries to execute both vars as a single command
bash: echo foo: command not found
$ "$var1" "$var2"
+ 'echo ' foo ### The shell tries to execute 'echo ' (echo with a space)
bash: echo foo: command not found
So, the right way is to remove the space and quote each variable separately:
$ var1="echo"
$ var2="foo"
$ "$var1" "$var2"
If you do that though, you'll hit the next error. The .
is the source
command. That tries to read a shell script and execute it in the current session. You are giving it a php script instead. That won't work, you need to execute it, not source it.
Finally, always avoid using CAPITAL variable names. The shell's reserved variables are capitalized so it's a good idea to always use lower case variable names for your scripts.
Putting all this together (with a few other minor improvements), what you want is something like:
#!/bin/sh
list="/path/to/my/site/dir"
config="/usr/bin/php"
for i in "$list"
do
"$config" "$i"/test.php
done
Best Answer
When you start your script a new process is created that only inherits your environment. Your current environment stays as it is. You can start your script like this if you want to change the current directory from a script:
or
The
.
(source
is the long version of.
) will evaluate the script in the current environment so it might be altered.Sources: