【问题标题】:symbols in command line argument.. python, bash命令行参数中的符号.. python,bash
【发布时间】:2011-02-19 20:53:15
【问题描述】:

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

有什么解决办法吗?

【问题讨论】:

    标签: python bash command-line-arguments


    【解决方案1】:
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-29
      • 2022-07-26
      • 2012-08-15
      • 2011-05-31
      • 1970-01-01
      • 2023-02-14
      • 1970-01-01
      • 2011-07-14
      相关资源
      最近更新 更多