Filter shell script to find lines that contain all specified patterns
join is the name of a common Unix command, so using that name for your function could create confusion.

I don't recommend munging the patterns to dynamically write an awk program.  As you pointed out, your technique is vulnerable to injection, resulting in execution of arbitrary awk code.  Instead, I'd write a fixed awk script that does the job.



#!/usr/bin/env awk -f

BEGIN {
    # Treat command-line arguments as patterns rather than input filenames.
    for (i = 1; i &lt; ARGC; i++) {
        patterns[i - 1] = ARGV[i];
    }
    # Truncate argument list, so that awk always read from standard input.
    ARGC = 1;
}

{
    for (i in patterns) {
        if (!match($0, patterns[i])) {
            next;
        }
    }
    print;
}


To search for literal strings instead of regular expressions, use the index(haystack, needle) function instead of match(haystack, needle).