代码之家  ›  专栏  ›  技术社区  ›  Shiv Deepak

命令行参数中的符号..蟒蛇

  •  1
  • Shiv Deepak  · 技术社区  · 16 年前

    我正在使用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
    

    有什么解决办法吗?

    2 回复  |  直到 16 年前
        1
  •  10
  •   LukáÅ¡ Lalinský    16 年前

    是的,引用字符串是唯一的方法。bash有它的语法和一些字符有特殊的含义。顺便说一句,使用“”还不够,请改用撇号。有些字符仍将用普通引号解释:

    $ echo "lots of $$"
    lots of 15570
    $ echo 'lots of $$'
    lots of $$