Function to run a progress bar in zenity

First off, I'm a novice in bash...
I'm trying to make a progress bar in zenity to show progress of a file download. When complete, the progress bar should exit. I'm using a function for the progress bar. Any help appropriated.
My code is :

#!/bin/bash

progress_bar()
{

(
while :
do

# =================================================================
echo "# Uploading" ; sleep 2
echo "25"
echo "# Uploading" ; sleep 2
echo "50"
echo "# Uploading" ; sleep 2
echo "75"
echo "# Uploading" ; sleep 2
echo "99"
echo "# Uploading" ; sleep 2
done

)  |
`zenity --progress  --title="Progress Status"  --auto-close  --auto-kill 2>&1`
a=111
echo $a
(( $? != 0 )) && zenity --error --text="Error in zenity command."

exit 0
}

while :
do
  progress_bar &  `curl  -o "bigfile222"    <downloadurl> 2>/dev/null`

wait $(jobs -p)
done
exit
~     

curl has a built-in progress meter that's probably better and more honest than anything hacked from the outside. I strongly suggest you use it.

A good start would be removing the useless backticks ` ` you've put around curl. This will allow you to see what curl's printing. Perhaps it can be piped into zenity somehow.

curl also has an alternate, simpler-looking progress meter if you don't like the default, which you can tell it to use with curl -'#'

A little more experimenting today, I don't have zenity but do have curl, this extracts the percentage from the live download:

curl -o filename http://website/file 2>&1 |
        awk -v RS="\r" 'BEGIN { print "# Downloading file" } ; $1 ~ /[0-9]/ { print $1 }' | zenity --progress

I haven't tested the red bit, let me know how that goes.

You could also use wget with the --progress=bar option which writes to STDERR or another alternate would be pv. You probably have to do something a little odd with that though, such as:-

wget -O - "${source_url}" | pv options > ${target_file}

The options could include things such as a file size estimate so you can get a percentage done/remaining time estimate etc.

I'd only go for pv in this case if the curl or wget options are unavailable to you for some reason, e.g. you are capturing the output in a variable to use later on for some reason, however if that is the case, maybe you would be better to set off a background process to give you feedback, similar to this:-

:

target_file=/path/to/your/file
expected_size=1024000000           # Estimate on the file size
:
:
while :
do
   sleep 2
   current_size=$(stat -c %s ${target_file})
   ((percent_complete=(${current_size}*100)/${expected_size}))
   printf "\rDownload is %2.0d\% complete."
done &                 #   Loop in the background
bg_process_id=$!       # Get the process id of the background loop

curl -o "${target_file}" "${source_url}"
kill $bg_process_id

It's a bit messy, but could help if you read and process the STDOUT & STDERR from curl or wget.

I hope that this helps, but try the other suggestions first.
Robin