Need help matching a mattern using grep/egrep in bash scripting
问题 I am trying to match all characters of given string but those characters should match in the order as given to the bash script. while [[ $# -gt 0 ]]; do case $1 in -i) arg=$2 egrep "*[$arg]*" words.txt shift ;; esac shift done $ sh match_the_pattern.sh -i aei words.txt Should return words like abstentious adventitious sacrilegiousness If you notice, first a is matched then e and then i , all of them are in order. Plus, the whole word is matched and filtered. 回答1: Change this: arg=$2 egrep "*[