我有一个脚本,我从命令行运行,我希望能够将字符串参数传递给.如在
script.py --string "thing1\nthing2"
Run Code Online (Sandbox Code Playgroud)
这样程序会将'\n'解释为新行.如果string="thing1\nthing2"我想得到
print string
Run Code Online (Sandbox Code Playgroud)
回来:
thing1
thing2
Run Code Online (Sandbox Code Playgroud)
而不是 thing1\nthing2
如果我只是将字符串"thing1 \nthing2"硬编码到脚本中,它会执行此操作,但如果它通过getopt作为命令行参数输入,则它无法识别它.我已经尝试了很多方法:在cl字符串中读取,r"%s" % arg在命令行上指定它的各种方法等,似乎没有任何工作.想法?这完全不可能吗?
首先来看看这个问题: 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.