shell支持set吗?

发布于 2024-12-02 20:13:48 字数 68 浏览 0 评论 0原文

bash 和 ksh 等 shell 是否支持集合操作(​​例如“两个集合的并集”)?我无法使用谷歌找到任何关于此的教程。

Do shells such as bash and ksh support set operations (such as 'union of two sets')? I can't find any tutorial about this using Google.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

故人的歌 2024-12-09 20:13:48

据我所知,POSIX shell(包括bash)不支持集合操作。但是您可以构建自己的数组,例如,通过使用 bash 关联数组(bash 4.0 及更高版本)。

As far as I know, POSIX shell (including bash) doesn't support sets operation. But you can build your own, for example, by making use of bash associative array (bash 4.0 and later).

对岸观火 2024-12-09 20:13:48

No bash/ksh 不支持专用集操作。如果您坚持使用 shell,则必须自己编写程序。就像 xdazz 提供的链接所做的那样。如果您想要完全专用的集合操作(​​也在性能方面),请使用真正的编程语言(例如Python、Ruby等)

No bash/ksh doesn't support dedicated sets operations. You will have to program your own if you insists on using the shells..like what the link xdazz provided has done. If you want full dedicated set operations (also in terms of performance), use a real programming language (eg Python, Ruby etc )

幻想少年梦 2024-12-09 20:13:48

它可以通过编写类似于在 Makefile 中编写的定义来执行设置操作:

someUnion: "file-1.txt" \/ "file-2.txt"
someIntersection: "file-1.txt" /\ "file-2.txt"
someDifference: someUnion - someIntersection

它非常酷,您应该检查一下。我个人不推荐“unix shell 中的设置操作”帖子。当您确实需要执行许多集合操作或者您有任何相互依赖的集合操作时,它不会很好地工作。

无论如何,我认为它非常酷,你应该完全检查一下。

I wrote a program recently called Setdown that does Set operations from the cli.

It can perform set operations by writing a definition similar to what you would write in a Makefile:

someUnion: "file-1.txt" \/ "file-2.txt"
someIntersection: "file-1.txt" /\ "file-2.txt"
someDifference: someUnion - someIntersection

Its pretty cool and you should check it out. I personally don't recommend the "set operations in unix shell" post. It won't work well when you really need to do many set operations or if you have any set operations that depend on eachother.

At any rate, I think that it's pretty cool and you should totally check it out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文