【发布时间】:2019-06-20 19:22:44
【问题描述】:
我想完全按照他们输入的方式获取用户命令。唯一允许的区别是' 可以代替",反之亦然。
例如,如果用户键入。
node test.js git commit -m "first message"
我想在控制台上记录以下任何一个。
You typed: git commit -m 'first message' //line A
You typed: git commit -m "first message" //line B
但是有不可接受的:
You typed: "git" "commit" "-m" "first message" //line C
You typed: 'git' 'commit' '-m' 'first message' // line D
正如您在上面看到的,引号可以与用户提供的不同(' 可以替换 ",反之亦然,如 B 行),但不能错位(如 C 和 D 行) .希望这很清楚。
编辑: 编辑了整个问题以避免混淆。
【问题讨论】:
-
引号在传递给节点之前由 shell 解释,因此如果没有显式转义和引用整个命令(例如
"git commit -m \"first message\""),您可能无法执行您想要的操作。跨度> -
乔...我进行了编辑。你能告诉我这是否可能吗?
-
编辑不清楚,请准确说明您想要什么而不是不可接受的结果
-
我编辑了这个问题。希望这很清楚。
标签: node.js