在 for...done 循环中移动匹配 glob 的文件 returns 'no such file or directory'

Move files matching glob in for...done loop returns 'no such file or directory'

我正在根据文件的扩展名移动文件。

当存在与 glob 匹配的文件时,以下将按预期工作;但是当没有匹配的文件时 returns

'mv: rename /Users/xxx/Downloads/*.txt to /Volumes/Internal_HD/*.txt: no such file of directory'

in_path=/Users/xxx/Downloads
out_path=/Volumes/Internal_HD

for f in "$in_path"/*.txt; do
    mv -v "$f" "$out_path"
done;

['xxx' 是用户名。]

设置 nullglob 选项,否则如果没有文件匹配,模式将扩展为自身:

shopt -s nullglob