bash:嵌套双引号和美元符号

bash: nested double quote and dollar sign

sh -c "$(curl -Ls "https://my-domain.com/a.sh?v=$(date +%s)")"

我想执行一个远程 sh 文件并确保没有缓存正在使用。

我知道上面的命令可以用,但是放在markdown文档上对语法高亮不友好

嵌套双引号和 $ 符号命令的正确写法是什么?

这是正确的方法。如果语法高亮器没有正确高亮它(例如在 Stack Exchange 上,哈哈),那是语法高亮器的错。 chepner explains :

That's a problem with the syntax highlighter, not your code. It stems from the fact that most syntax highlighters use regular expressions for speed and simplicity, and the new quoting context established by a command substitution is non-regular.

但是,William Pursell said

For this case, you could just avoid nesting and do curl -Ls ... | sh

curl -Ls "https://my-domain.com/a.sh?v=$(date +%s)" | sh

相关