我正在编写的脚本试图找出不匹配的模式,其中模式作为 bash 变量提供给 grep 函数。现在的变量只包含一种模式,即“tmp$”,用于 grep 以 tmp 结尾的记录。这是它的代码
cat file | grep -v -F "${EXCLUSIONS}"
其中 EXCLUSIONS 是变量
cat file:
/bin/xyz
/bin/abc
/tmp/dir/abc
/helloworld/tmp
echo $EXCLUSIONS:
tmp$
/bin
#Here I want the output to be only /tmp/dir/abc as one pattern\
#to exclude is anything that ends with tmp or /bin
输出仍然包含以 tmp 结尾的条目,我认为这是因为它没有将tmp$末尾的$视为正则表达式模式。bash 中有没有办法实现这种工作,我可以使用像 EXCLUSION 这样的变量,它可以包含正常模式和带有元字符(如 $ 或 ^)的模式作为正则表达式工作?