strace、cp、awk、およびstatを使用して、プログレスバー付きのcpを作成するスクリプトがあります。cpを呼び出すコードの部分は次のとおりです。
strace -q -ewrite cp -- `printf '%q ' $@` 2>&1 | awk {Lots of code here}
問題は、スペースを入れて何もコピーできないことです。スペースで機能するように、このスクリプトをどのように変更する必要がありますか?ありがとう
編集:出力は次のとおりです。
matt: ~/tmp $ bash -x cp-progress "q" "file"
++ printf '%q ' q file
++ stat -c %s q
+ strace -q -ewrite cp -- q file
+ awk '{
count += $NF
if (count % 10 == 0) {
percent = count / total_size * 100
printf "%2d%% [", percent
for (i=0;i<=percent / 2;i++)
printf "→"
printf "→"
printf "]\r"
}
}
END { print "" }' total_size=5242880 count=0
100% [→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→→]
matt: ~/tmp $ bash -x cp-progress "q" "file with spaces"
++ printf '%q ' q 'file with spaces'
+ strace -q -ewrite cp -- q 'file\' 'with\' spaces
++ stat -c %s q
+ awk '{
count += $NF
if (count % 10 == 0) {
percent = count / total_size * 100
printf "%2d%% [", percent
for (i=0;i<=percent / 2;i++)
printf "→"
printf "→"
printf "]\r"
}
}
END { print "" }' total_size=5242880 count=0
0% [→→]
最初のものを見ますか?これは正常に機能し、実行されcp -- q file
ます。さて、次は、cp -- q 'file\' 'with\' spaces
どうすれば修正できますか?