String.raw
似乎是一個正確的方式來編寫嵌入式命令狀如何打印「 1」使用ES6 String.raw
const command = String.raw`sed -n 's/${hash} \(.*\)/\1/p'
但是,這是行不通的,因爲\1
不能在字符串寫入.RAW,問題如下所示:
console.log(String.raw`\1`)
=>SyntaxError: Octal literals are not allowed in template strings.
console.log(String.raw`\\1`)
\\1
有這將允許這個建議:https://github.com/tc39/proposal-template-literal-revision – Bakkot