Does the shell support sets?
Asked Answered
G

4

1

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.

Griff answered 6/9, 2011 at 2:17 Comment(0)
E
4

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

Evelinaeveline answered 6/9, 2011 at 2:22 Comment(0)
H
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).

Hereditable answered 6/9, 2011 at 2:28 Comment(0)
G
0

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 )

Gullah answered 6/9, 2011 at 2:37 Comment(0)
A
0

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.

Adrial answered 30/1, 2015 at 1:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.