Friday 9 November 2018

linux - eval and export remove the double quote (") from the string





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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...