My sh is bash. I need a percentile progress indicator for my 0~9999 'for' loop... So I use this lines within the loop, but the output is very strange.
#!/bin/bash
declare -i percentile
for((i=0;i<=9999;i++))
do
percentile=($i+1)%100
if [ "$percentile" == 0 ];then
echo -ne $((($i+1)/100))\%\r
fi
done
echo -n '\n'
What I want to see is it outputs '1%' and then replace this line with '2%' and '3%' ... but not '1%', '2%', '3%', ... line by line.
After execute this .sh file, what displayed on the terminal is
-ne 1%r
-ne 2%r
-ne 3%r
-ne 4%r
-ne 5%r
-ne 6%r
-ne 7%r
-ne 8%r
-ne 9%r
-ne 10%r
...
The bash just didn't recognize the '-ne' option and the escaped '\r' for 'echo' command, what should I do to solve this problem?
sh
is? – heemayl Feb 13 '17 at 03:53printf
instead? – Sparhawk Feb 13 '17 at 03:56