Exact Matching
This style of matching that I have used so far is called exact matching. It is simple to use, but you must take precaution that your patterns do not look like any of interact’s flags. Rather than memorizing them, the simplest way to prevent this from happening is to use the -ex flag. This is especially useful when patterns are stored in a variable.
interact {
-ex $var action1
-ex "-ex" action2
}The first pattern above matches whatever is stored in the variable var. The second pattern matches the string -ex itself. Without the -ex flag, interact would look for action2.
Most of the time, you will not need to use -ex and you should not feel obliged to use it. The -ex flag is only necessary to match patterns that would otherwise be accepted as a keyword (e.g., eof, timeout) or a flag (any argument starting with a hyphen).
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access