I am running the following bash script. When I use variables with whitespaces, when I use them, single quotes are added. It is not the result that I expect.
My scripts:
#!/bin/bash -x
KEY="x"
VALUE="b c"
VARS="$KEY=\"$VALUE\""
KEY="y"
VALUE="d e"
VARS="$VARS $KEY=\"$VALUE\""
env $VARS printenv
When I run it in debug mode I get this result
+ KEY=x
+ VALUE='b c'
+ VARS='x="b c"'
+ KEY=y
+ VALUE='d e'
+ VARS='x="b c" y="d e"'
+ env 'x="b' 'c"' 'y="d' 'e"' printenv
env: c": No such file or directory
But I need the following result:
env 'x="b' 'c"' 'y="d' 'e"' printenv
How do I prevent single quotes from being added?
When I run this line, It works well: env x="b c" y="d e" printenv
Thanks