I want to export a string with eval in the following way. But I get the string without quotes as indication in the following example
root@linux:~# a="{\"name\":\"any\"}"
root@linux:~# echo $a
{"name":"any"}
root@linux:~# eval "export -- \"b=\"\"$a\"\"\""
root@linux:~# echo $b
{name:any} ------>> expect {"name":"any"}
How to solve this problem?
Answer
I'm going to set aside that I don't quite understand why you are doing it like this, but try the following:
bash-3.2$ a="{\"name\":\"any\"}"
bash-3.2$ echo $a
{"name":"any"}
bash-3.2$ eval "export -- b='$a'"
bash-3.2$ echo $b
{"name":"any"}
bash-3.2$
No comments:
Post a Comment