Does the shell support sets?

杀马特。学长 韩版系。学妹 提交于 2019-12-13 00:36:03

问题


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.


回答1:


What about this set-operations-in-unix-shell.




回答2:


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).




回答3:


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 )




回答4:


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.



来源:https://stackoverflow.com/questions/7314319/does-the-shell-support-sets

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!