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.
I might be misunderstanding what you want, but you can try using an array instead of a simple variable.
I suspect that's a little too simple for you, as "exporting" an array doesn't really work. I think
bashdoes a little sleight-of-hand to make "exported" arrays visible to subshells, but strictly speaking an environment variable is simply a named string without any other type of structure.How is
MYCMDbeing used, exactly? Which file do you place it in? Changes to the environment persist, so if you were to setFOO="123 456"in the environment of the command that starts Apache, Apache would inheritFOOas well.