Bash:单引号变量

Doc*_*iki 4 python linux bash command-line googlecl

首先来看看这个问题: Bash或GoogleCL:字符串参数中的新行

我想现在在"摘要"中添加一个变量$ {date}:

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.'
Run Code Online (Sandbox Code Playgroud)

但变量不会在bash中的单引号内扩展.

有可能这样做吗?

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

Wil*_*ell 14

而不是尝试在单个带引号的字符串中扩展变量,典型的解决方案是连接单引号和双引号字符串.换一种说法:

'Today is'"${date}"'. Poor' ...


Gor*_*son 4

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

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