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

2016-03-22 00:11:42 +08:00
 douya0808
原文:
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"是什么意思腻?可否指点一下下?
1694 次点击
所在节点    问与答
9 条回复
ahcat
2016-03-22 00:15:52 +08:00
引号内的空格不视作分隔符
MCVector
2016-03-22 00:18:01 +08:00
双引号,单引号内或者是被转义的空格不会被当成分隔符。
douya0808
2016-03-22 09:42:48 +08:00
@MCVector 前辈您好,想问下您是怎么看出"不会被当成分隔符"的呀?我看不出来这里有否定的意思。

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

测试后发现被双引号扩起来的括号果然不会被当作分隔符了,但是这个文档里您是怎么看出这个否定意思的呢?嘻嘻:)
douya0808
2016-03-22 09:46:14 +08:00
@ahcat 您好,您是怎么看出 which 中的否定含义的呢?:)
ahcat
2016-03-22 10:10:38 +08:00
which
can be protected
by :
1. double quotes
2. single quotes
3. backslash
MCVector
2016-03-22 10:22:19 +08:00
@douya0808 "protected from" 保护(空格)免受 (xarg)的影响。
MCVector
2016-03-22 10:24:39 +08:00
@douya0808 看错了… 这句话应该是 可以用 单双引号和转义来保护不想被 xard 处理的空格。
MCVector
2016-03-22 10:25:42 +08:00
@douya0808 * xargs (抱歉手机屏幕小全是 typo)
douya0808
2016-03-22 10:26:44 +08:00
@MCVector 哈哈,我也懵了您这么一说确实是这样,被括起来的多个 blanks 就不会被作为 delimiter 了,意思是这个意思,但是看不懂文档实在是难受呀哈哈哈哈:)

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/265299

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX