#!/usr/bin/env bash
shopt -s expand_aliases

add_filter () {
    local name=$1 c=${name}_count;
    shift;
    alias ${name}$(($c=c+1))="$(printf "%q " "$@")" ;
}

run_filter () {
    local name=$1 c=${name}_count;
    if ((c<1)); then 
	cat
    else 
	local filter=${name}1 i
	for ((i=2;i<=c;i++)); do
	    filter=${filter}'|'${name}$i
	done
	eval $filter
    fi
}

clear_filter () {
    local i name=$1 c=${name}_count;
    for ((i=1;i<=c;i++)); do
	unalias ${name}$i
    done
    unset $c
}

add_filter myfilter grep 'foo bar'
add_filter myfilter grep 'bleh'
printf "%s\n" 'foo bar' 'foo bar bleh' 'bleh buz' | run_filter myfilter
clear_filter myfilter