Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex ';查找';使用带有变量的正则表达式_Regex_Bash_Find - Fatal编程技术网

Regex ';查找';使用带有变量的正则表达式

Regex ';查找';使用带有变量的正则表达式,regex,bash,find,Regex,Bash,Find,请帮我做以下几件事: 设为三个文件: file-aaa.sh file-bbb.sh file-xxx.sh 在bash脚本中,我有变量 $a=aaa $b=bbb 现在,我想执行如下操作: find . -name "file-[$a|$b].sh" 并期望在输出中获得两个文件。 我做错了什么?您可以使用此查找: find . -name "file-$a.sh" -o -name "file-$b.sh" 要使用-regex选项将其合并为一个: 在OSX上: find -E .

请帮我做以下几件事:

设为三个文件:

file-aaa.sh 
file-bbb.sh
file-xxx.sh
在bash脚本中,我有变量

$a=aaa 
$b=bbb
现在,我想执行如下操作:

find . -name "file-[$a|$b].sh"
并期望在输出中获得两个文件。 我做错了什么?

您可以使用此查找:

find . -name "file-$a.sh" -o -name "file-$b.sh"
要使用
-regex
选项将其合并为一个:

在OSX上:

find -E . -regex ".*file-($a|$b)\.txt"
find . -regextype posix-extended -regex ".*file-($a|$b)\.txt"
在Linux上:

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