有人能告诉我是否应该在shell脚本中包含变量的引号?
例如,以下是正确的:
xdg-open $URL
[ $? -eq 2 ]
Run Code Online (Sandbox Code Playgroud)
要么
xdg-open "$URL"
[ "$?" -eq "2" ]
Run Code Online (Sandbox Code Playgroud)
如果是这样,为什么?
首先来看看这个问题: 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.
这有效:
ghost=$'\U1F47B'
PROMPT='time: %T $ghost > '
Run Code Online (Sandbox Code Playgroud)
但是有没有办法内联 Unicode 字符的十六进制版本呢?