Bash:单引号中的variables

首先看一下这个问题: Bash或者GoogleCL:string参数中的新行

现在我想添加一个variables$ {date}到“summary”中:

google youtube post ~/videos/cat-falls-down-stairs.avi Comedy \ --tags 'currency of the internet' \ --summary $'Today is ${date}. Poor whiskers takes a tumble.\nShe'\''s fine, though, don'\''t worry.' 

但variables不会在bash中的单引号内部展开。

有可能做到这一点?

注意: GoogleCL是一个用python编写的命令行程序。 我使用Python 2.6在Ubuntu 10.10上。

我将在列表中添加另一个选项:将变量定义为换行符,然后在双引号内使用该变量。

 nl=$'\n' ... --summary "Today is ${date}. Poor whiskers takes a tumble.${nl}She's fine, though, don't worry." 

通常的解决方案是连接单引号和双引号的字符串,而不是尝试在单引号字符串中展开变量。 换一种说法:

 “今天是”“$ {date}”“。 较差的' ...

变量不会在单引号内扩展。 要么你可以像William建议的那样做,要么你可以把行改写成双引号,这样可以随意扩展变量。

 "Today is ${date}. Poor whiskers takes a tumble.\nShe's fine, though, don't worry." 

奖金:这样做,你将不必逃避你的单引号。

现在我读链接,你说\ n不会扩大。 解决方法是这样的:

 --summary $(echo -e "Today is...") 

使用这个子shell是一个粗糙的,但它会节省您的反引号的引号。