'find' using regex with variables

bash, find, regex

Solution

You can use this find:

find . -name "file-$a.sh" -o -name "file-$b.sh"

To combine it into one using `-regex` option:

On OSX:

find -E . -regex ".*file-($a|$b)\.txt"

On Linux:

find . -regextype posix-extended -regex ".*file-($a|$b)\.txt"

Problem

Please, help me with the following: Let it be three files: ``` file-aaa.sh file-bbb.sh file-xxx.sh ``` In a bash script I have variables ``` $a=aaa $b=bbb ``` Now, I want to execute something like: ``` find . -name "file-[$a|$b].sh" ``` and expect to get two files in output. What am I doing wrong?

Original source