Need help working with pv's -s SIZE argument

I am having trouble with the -s SIZE argument for pv, I get the size of the file and directory that I am working with this code:

size=du -b | grep -v '/' | awk '{print $1}'

As you can see the size gets put in a variable called size, but the problem comes when I need to tell pv if this is it bites, kilobytes, megabytes, gigabytes, etc. The ways I have tried are:


pv -pterb -s ($size)k
pv -pterb -s "$size"k
pv -pterb -s $sizek
pv -pterb -s $size\k

All my tries have ended in a failure.

“We must plan for freedom, and not only for security, if for no other reason than only freedom can make security more secure.” Karl Popper

Can you move the ‘k’ to where your setting $size?

size="`du -b | grep -v '/' | awk '{print $1}'`k"

When I dump that in a test script and echo $size I get the following:

135308350986k

I don’t think pv likes something that

size="`du -b | grep -v '/' | awk '{print $1}'`k"

is doing because when I use it with pv I get this

pv: option requires an argument – ‘s’
Try `pv --help’ for more information.

pv does have the $size variable for -s

You code should be:


size=`du -b | grep -v '/' | awk '{print $1}'` (Same as yours)
pv -pterb -s "${size}"k

That should do the trick. Let us know if that worked.

  • Thejaswi Raya

Maybe modify what you have because now I get then

pv: -s: integer argument expected

maybe it should be something like:

pv -pterb -s "${size}k"

Quite possible. Does “${size}k” work now?

No it has the same error as before.