Pergunta

I have the following code:

export VAR1=FINAL_VAL="\"--value1 --value2\""
export $VAR1

After executing this I would expect FINAL_VAR=--value1 --value2, but on the second export I get "bash: export: `--value2"': not a valid identifier", like if quotation marks where not detect correctly, and if I execute

echo export $VAR1

I get

export FINAL_VAL="--value1 --value2"

Which if copy and paste it into the console I will get FINAL_VAR=--value1 --value2, however when executing from export (export $VAR1) or from (`echo export $VAR1`) It does not export.

It seems that it doesn't like/detect the quotation marks, but I tried scaping them many ways without any luck.

Did someone experienced something like this and could tell me how to workaround it?

Thanks beforehand,

Foi útil?

Solução

You have to do export "$VAR1", notice the quotes

Outras dicas

You can get rid of error

export: `--value2"': not a valid identifier 

by simple quotes:

export "$VAR1"

And reason its not getting exported when you do

(export $VAR1) 

or

(`echo export $VAR1`) 

because you are exporting it in a subshell () which exists as soon as command exits. You should not use it if you need to export some variable to shell environment, because subshell(a child of parent shell) cannot modify parent's environment.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top