3

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?

1 Answer 1

12

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" 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.