I am trying to write an expect script that once started will watch my terminal and run a command every time that it finds a match.Is this even possible with expect?  If so, would expect_background be the right thing to use?EDIT: For clarity, I am trying to expect the output from my terminal, not the input...
Can I have a (bash) shell with expect running in the background?
bash;shell;shell script;expect
Yes, you can do this just with bash: redirect stdout to a tee process that can do something when your patterns are seen. tee is good because it also puts stdout on stdout.exec 1> >(tee >(awk '/foobar/ {print *** DING DING ***}'))This sends stdout to process substitution 1, tee, which copies it's stdin to both stdout and process substitution 2, an awk script that does something. You could put your code, or the path to a script, in the inner process substitution.To demonstrate$ echo this is foobar stuffthis is foobar stuff$ exec 1> >(tee >(awk '/foobar/ {print *** DING DING ***}'))$ dateThu Mar 10 16:37:14 EST 2016$ pwd/home/jackman$ echo this is foobar stuffthis is foobar stuff*** DING DING ***