简体   繁体   English

双引号字符串转义节点eval javascript

[英]Double quote string escape node eval javascript

I have a node file with this content inside: 我有一个节点文件,其中包含以下内容:

console.log("hello \"\"world")

When I log this I get: 当我登录时,我得到:

hello ""world

I would like to put this in node's -e (eval) flag. 我想把它放在节点的-e(eval)标志中。

I'm conceptually not undestanding how I could "clean" this string so that it would give the same output. 从概念上讲,我并不理解如何“清理”此字符串,以便产生相同的输出。

node -e "console.log(\"hello \\"\\"world\")"
hello \world

This works but adds an extra slash 这有效,但增加了一个斜线

What would I have to do with the contents of the eval to make it valid and work as expected? 为了使eval有效并按预期工作,我将如何处理它的内容?

You need two more slashes: 您还需要两个斜杠:

node -e "console.log(\"hello \\\"\\\"world\")"

Both the \\ and the " need to be escaped. \\"需要转义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM