Bash:单引号/双引号中的变量扩展
我想在下面的bash脚本中添加一个变量${date}
:
ffmpeg -i in.flv -vf drawtext="fontfile=Sans.ttf:text='Today is ${date}':fontsize=6" out.flv
显然,${date}
不会在单引号中扩展,另请注意单引号之外还有双引号,这使得它变得更加复杂。
多谢。我在 CentOS 6 上。
I want to add a variable ${date}
in the following bash script:
ffmpeg -i in.flv -vf drawtext="fontfile=Sans.ttf:text='Today is ${date}':fontsize=6" out.flv
Obviously, ${date}
won't expand in single quote, please also note that there is a double quote beyond the single quote, which makes it even more complicated.
Thanks a lot. I am on CentOS 6.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
${date}
被扩展,因为它位于双引号之间(双引号内的单引号只是字符)测试它:
${date}
is expanded because it is between double quotes (the single quotes inside the double quotes are just characters)Test it with:
您的
${date}
将正确扩展。正如您自己所说,您用双引号将整个字符串括起来,并且 bash 会将变量扩展为双引号。事实上,有内部单引号根本不重要:
Your
${date}
WILL expand correctly. As you said yourself, you surround the whole string with double quotes, and bash will expand variables into double quotes.The fact that there are inner single quotes does not matter at all: