I have simplified this scenario as much as I can. I am trying to get the second version to work with proper escaped quotes. The first works as expected. Unfortunately I cannot change how the second is going to be called. I am however able to change the value of REALTEST. No matter what I tried with quoting, I can't get the second to accept the spaced string.
This is what I am trying to do:
#!/bin/bash -x
env -i TESTVAR="some spaced string" /bin/bash -l -c "echo $TESTVAR"
REALTEST=TESTVAR="some spaced string"
env -i $REALTEST /bin/bash -l -c "echo $TESTVAR"
Here is my output:
-bash-4.2$ ./test.sh
+ env -i 'TESTVAR=some spaced string' /bin/bash -l -c 'echo $TESTVAR'
some spaced string
+ REALTEST='TESTVAR=some spaced string'
+ env -i TESTVAR=some spaced string /bin/bash -l -c 'echo $TESTVAR'
env: spaced: No such file or directory
Any thoughts on what approach I can take to solve this or is this just flat out not possible?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…