击:变量单引号 [英] Bash: Variable in single quote

查看:168
本文介绍了击:变量单引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先来看看这个问题:
<一href=\"http://stackoverflow.com/questions/4918067/bash-or-googlecl-new-line-in-a-string-parameter\">Bash或GoogleCL:在一个字符串参数新行

First take a look at this question: Bash or GoogleCL: new line in a string parameter

我想补充一个变量$ {DATE}进入摘要现在:

I want to add a variable ${date} into the "summary" now:

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.'

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

but variable wont expand inside single quote in bash.

是可以做到这一点?

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

Note: GoogleCL is a command-line program written in python. I am on Ubuntu 10.10 with Python 2.6.

推荐答案

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

I'll add yet another option to the list: define a variable as newline, then use that inside double-quotes.

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

这篇关于击:变量单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆