douya0808
V2EX  ›  问与答

钻牛角尖的问下关于 man xargs 中的一句话

  •  
  •   douya0808 · Mar 22, 2016 · 2934 views
    This topic created in 3879 days ago, the information mentioned may be changed or developed.
    原文:
    xargs reads items from the standard input, delimited by blanks (which can be protected with double or single quotes or a backslash) or newlines

    测试:
    [root@localhost ~]# cat xxxx
    1 2 3 4 5
    6 7 8 9
    10 11
    [root@localhost ~]# cat xxxx | xargs
    1 2 3 4 5 6 7 8 9 10 11

    原来单空格、多空格、 Tab 都会被作为分隔符进行分割,但括号中的那句"which can be protected with double or single quotes or a backslash"是什么意思腻?可否指点一下下?
    9 replies  •  2016-03-22 10:26:44 +08:00
    ahcat
    ahcat
    Mar 22, 2016 via iPhone
    1
    引号内的空格不视作分隔符
    MCVector
    MCVector
    Mar 22, 2016
    2
    双引号,单引号内或者是被转义的空格不会被当成分隔符。
    douya0808
    douya0808
    OP
    Mar 22, 2016
    3
    @MCVector 前辈您好,想问下您是怎么看出"不会被当成分隔符"的呀?我看不出来这里有否定的意思。

    [root@localhost home]# cat xxxx
    1 2 3" "4 5
    [root@localhost home]# cat xxxx | xargs
    1 2 3 4 5

    测试后发现被双引号扩起来的括号果然不会被当作分隔符了,但是这个文档里您是怎么看出这个否定意思的呢?嘻嘻:)
    douya0808
    douya0808
    OP
    Mar 22, 2016
    4
    @ahcat 您好,您是怎么看出 which 中的否定含义的呢?:)
    ahcat
    ahcat
    Mar 22, 2016
    5
    which
    can be protected
    by :
    1. double quotes
    2. single quotes
    3. backslash
    MCVector
    MCVector
    Mar 22, 2016
    6
    @douya0808 "protected from" 保护(空格)免受 (xarg)的影响。
    MCVector
    MCVector
    Mar 22, 2016
    7
    @douya0808 看错了… 这句话应该是 可以用 单双引号和转义来保护不想被 xard 处理的空格。
    MCVector
    MCVector
    Mar 22, 2016
    8
    @douya0808 * xargs (抱歉手机屏幕小全是 typo)
    douya0808
    douya0808
    OP
    Mar 22, 2016
    9
    @MCVector 哈哈,我也懵了您这么一说确实是这样,被括起来的多个 blanks 就不会被作为 delimiter 了,意思是这个意思,但是看不懂文档实在是难受呀哈哈哈哈:)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5187 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 06:31 · PVG 14:31 · LAX 22:31 · JFK 01:31
    ♥ Do have faith in what you're doing.