Bin Bash脚本速度很慢

Bin Bash脚本速度很慢,bash,performance,Bash,Performance,我对这件事一无所知,但我一直负责调查。有人能告诉我为什么这会很慢吗?或提供任何变更/替代方案 #!/bin/bash target="/Users/mariya/Desktop/Distribution" echo “Target is something” pushd "$target" > /dev/null FILES="./*.pdf" for f in $FILES do # Remove spaces from file mv "$f" "${f//[[:space

我对这件事一无所知,但我一直负责调查。有人能告诉我为什么这会很慢吗?或提供任何变更/替代方案

#!/bin/bash

target="/Users/mariya/Desktop/Distribution"
echo “Target is something”
pushd "$target" > /dev/null

FILES="./*.pdf"
for f in $FILES
do
  # Remove spaces from file
  mv "$f" "${f//[[:space:]]}"
done

let count=0
for f in *
do
    echo "Now printing: "  $f
    lpr -single -o landscape -o media=Custom.8.5x11in -o scale=100 -o page-ranges=1 $f
    echo "Printing Complete"
    let count=count+1
done
popd
echo ""
echo "Total Printed: $count"

哪个部分比较慢,重命名循环还是打印循环?目录有多大<代码>中的f*可能很大。另外,进行
lpr
需要多长时间?也许这可能是你的瓶颈。我认为您可能需要提供更多的计时信息,以便我们可以帮助您将
set-x
放在脚本的开头。然后,您将在执行每一行时看到它,因此您应该能够看到它所花费的时间。请注意,
mv
命令可能会无意中覆盖现有文件。例如:
上帝现在在这里.pdf
/
上帝不在任何地方.pdf
-->
上帝不在任何地方.pdf