Print loop output on same line dynamically

Hi,

I am trying to print copy percentage completion dynamically by using the script below,

#!/bin/bash
dest_size=0
orig_size=`du -sk $sourcefile | awk '{print $1}'`
while [ $orig_size -gt $dest_size ] ; do
   dest_size=`du -sk  $destfile | awk '{print $1}'`
coyp_percentage=`echo "scale=2; $dest_size*100/$orig_size" | bc`
echo "$coyp_percentage"
sleep 1
done

From above code am getting completion percentage on newline as below,

.84
1.97
3.38
8.75
15.81
23.72

But I need the output on same line with space separated dynamically.

Any help on this..

Note: Do i need to use OFS for this?

OS_ver:Sol_11.3x86
shell=bash

TIA

man bash :

Note:
echo -n is not part of the standard and echo -n is not implemented in a standardized way.

For reliable, portable results use printf instead:

printf "%s " "$var"

--
See:
echo
printf

1 Like

Thanks Scrutinizer ..it's working

A demonstration how bash's builtin echo works in reality

bash -c 'echo -n hello; uname -sr'
helloSunOS 5.11
bash --posix -c 'echo -n hello; uname -sr'
-n hello
SunOS 5.11
bash -c 'echo -n hello; uname -sr'
helloLinux 4.4.0-122-generic
bash --posix -c 'echo -n hello; uname -sr'
helloLinux 4.4.0-122-generic
1 Like