我正在使用API在Linux上为Twitter帖子编写一个python脚本,是否可以在不带撇号的情况下以明文形式传递“(”)等符号?
% ./twitterupdate this is me #works fine % ./twitterupdate this is bad :(( #this leaves a error on bash.
唯一的选择是将文本括在-->“”中吗?就像…
% ./twitterupdate "this is bad :((" #this will reduce the ease of use for the script
有什么解决办法吗?
是的,引用字符串是唯一的方法。bash有它的语法和一些字符有特殊的含义。顺便说一句,使用“”还不够,请改用撇号。有些字符仍将用普通引号解释:
$ echo "lots of $$" lots of 15570 $ echo 'lots of $$' lots of $$
http://www.gnu.org/software/bash/manual/bashref.html#Quoting