问题
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:
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"
来源:https://stackoverflow.com/questions/24552144/find-using-regex-with-variables