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 $
Change this:
arg=$2 egrep "*[$arg]*" words.txt
to this:
arg=$(sed 's/./.*[&]/g' <<< "$2") grep "$arg" words.txt
If that's not all you need then edit your question to clarify your requirements and provide more truly representative sample input/output.