Intersection of two lists in Bash

I’m trying to write a simple script that will list the contents found in two lists. To simplify, let’s use ls as an example. Imagine “one” and “two” are directories.

one=`ls one`
two=`ls two`
intersection $one $two

I’m still quite green in Bash, so feel free to correct how I am doing this. I just need some command that will print out all files in “one” and “two”. They must exist in both. You might call this the “intersection” between “one” and “two”.

5 Answers
5

Leave a Comment