String 如何在bash中匹配文件扩展名?

String 如何在bash中匹配文件扩展名?,string,bash,shell,string-matching,String,Bash,Shell,String Matching,我只想在文件名以.request结尾时调用函数,但如果request是子字符串,它会调用函数 我是进口零件,右边是输出 for file in ${filesOrDir[*]}; do if [[ -f "$file" ]]; then if [[ "$file"=*[".request"] ]]; then # Enters here when .request is a substring. fi fi

我只想在文件名以
.request
结尾时调用函数,但如果
request
子字符串,它会调用函数

我是进口零件,右边是输出

for file in ${filesOrDir[*]}; do    
    if [[ -f "$file" ]]; then
        if [[ "$file"=*[".request"] ]]; then
            # Enters here when .request is a substring.
        fi
    fi
    if [[ -d "$file" ]]; then
            # ... some logics       
    fi
done

尝试使用:
[[$file==*.request]]

handle request.sh
是检查文件名的帮助脚本

处理请求。sh:

while IFS='' read -r line || [[ -n "$line" ]]; do
    if [[ $line == *.request ]]; then
        echo $line
    fi
done < "$1"
hello.request
file name with space.request
输出:

while IFS='' read -r line || [[ -n "$line" ]]; do
    if [[ $line == *.request ]]; then
        echo $line
    fi
done < "$1"
hello.request
file name with space.request

在图片中有截图提供代码
[[$file=*.request]]
?是更好还是我应该把整个脚本放进去?祝你好运谢谢,这是我第二次。。。问题是如果我的文件名中有空格,上面的代码是否也有效?我用空格添加了添加输入选择答案投票下的
V
,使其变为绿色