I want to pass an environment variable with a space in it to apache. Apache uses env to start itself so in effect I have to make some thing like this work
export MYCMD=" env -i FOO=123\ 456"
$MYCMD
The result is
env: 456: No such file or directory
Looking at the strace output I see this
execve("/usr/bin/env", ["env", "-i", "FOO=123\\", "456"], [/* 41 vars */]) = 0
as you can see the env utility has split up my FOO variable into two other variables because of the space. I have tried all manner of options to try and maintain the space after env has digested the command but so far no luck.
You can try this on its own
env -i FOO=123\ 456
FOO=123 456
All is well
execve("/usr/bin/env", ["env", "-i", "FOO=123 456"],
The problem occurs when you place the command into another environment variable
Since this is what the Apache start up code does I am somewhat stuck with having to find a solution to this puzzle.
Many thanks in advance.
The problem would seem to be that the second level of quoting (the backslash in your eample) is not evaluated by a shell.
Is there a chance you can invoke your command like
instead?