bash - mv 尝试移动星号时出现问题

bash - mv 尝试移动星号时出现问题

我正在尝试制作一个脚本,将具有某些扩展名或属性的文件移动到另一个程序。一切都很好,脚本可以工作,但mv不断尝试移动语句文件。例如,这里是代码的一部分:

dirs=($(find "$dir" -type d))
for d in "${dirs[@]}"; do
for file in "$d"/*; do
    if [ -f "$file" ] && [ -x "$file" ]; then
        exefiles+=( "$file" )
        mv "$file" $bindir
    fi
done
    
for i in "${exefiles[@]}"; do
    echo "$i moved to $bindir" >> /home/$USER/$logname
done

for file in "$d"/lib*; do
    libfiles+=( "$file" )
    mv "$file" $libdir
done

for i in "${libfiles[@]}"; do
    echo "$i moved to $libdir" >> /home/$USER/$logname
done

for file in "$d"/*.c "$d"/*.cc "$d"/*.cpp "$d"/*.cxx; do
    srcfiles+=( "$file" )
    mv "$file" $srcdir
done
for i in "${srcfiles[@]}"; do
    echo "$i moved to $srcdir" >> /home/$USER/$logname
done

for file in "$d"/*.h "$d"/*.hxx; do
    incfiles+=( "$file" )
    mv "$file" $incdir
done

for i in "${incfiles[@]}"; do
    echo "$i moved to $incdir" >> /home/$USER/$logname
done
unset exefiles
unset libfiles
unset srcfiles
unset incfiles
cd "$d"
done

mv尝试移动"$d"/*等本身,并在终端和日志文件上打印出它不能移动。有什么办法可以预防吗,我做错了什么吗?

相关内容