You are not logged in.
Pages: 1
I'm trying to write a simple bash script which downloads the compat-wireless drivers and installs them. The script works fine but i'm trying to learn bash and would like to make it a bit nicer to look at and add some more functionality. What I have done is used grep to pull out the percentage of the download, however every number prints on a new line like so:
1%
2%
3%
4%
5%
6%
etc.... What I'm trying to do is replace the last percentage with the next one, so it's all on one line. I've had a look around and found that a way to do what I'm trying to do is with:
tput cbt
or with the bash escape codes directly. Now the thing is I don't know where I should put this in my code, could anyone help?
#!/bin/bash
#Retrieve latest compat-wireless soruces
echo -e "Downloading sources\n"
wget http://wireless.kernel.org/download/compat-wireless-2.6/compat-wireless-2.6.tar.bz2 |& grep -o "[0-9]\+%"
if test -fs compat-wireless-2.6.tar.bz2 then
echo "File Downloaded OK"
else
echo "Download Failed, Exiting."
exit
fi
#Untar folder
echo "Extracting sources"
tar jxvf compat-wireless-2.6.tar.bz2 > /dev/null
#Enter build folder
cd compat-wireless-*
#Select ath9k as driver to build
./scripts/driver-select ath9k
#Compile sources
make
#Install sources
sudo make install
#Unload wireless modules
sudo make unload wireless
#Reload ath9k module
sudo modprobe ath9k
#Return to original directory
cd ..
#Remove traces of install files
sudo rm -r compat-wireless-*
Offline
I have no bash skills, so this is a shot in the dark, but try passing the -n flag to echo
-n do not output the trailing newline
# edit: you could also take some pointers from here: http://mywiki.wooledge.org/BashFAQ/044
Offline
You will want to echo a carriage return (\r) or a backspace character (\b).
$ echo -e "Hi\bello"
Hello
M*cr*s*ft: Who needs quality when you have marketing?
Offline
Ok, so I've tried this with no luck, I'm not sure where I should be putting it...
#Retrieve latest compat-wireless soruces
echo -e "Downloading sources\n"
wget http://wireless.kernel.org/download/compat-wireless-2.6/compat-wireless-2.6.tar.bz2 |& grep -o "\r[0-9]\+%"
As the command needs to be in the same execution cycle as the wget and grep, yes?
Last edited by jack.mitchell (2011-01-18 12:27:09)
Offline
You need to use "\r" with printf not grep :-)
Offline
Ok, so I've tried
#Retrieve latest compat-wireless soruces
echo -e "Downloading sources\n"
wget http://wireless.kernel.org/download/compat-wireless-2.6/compat-wireless-2.6.tar.bz2 |& printf "\r `grep -o "\r[0-9]\+%"`"
To no avail, am I doing this correctly, or at least on the right lines? I can't seem to find any examples where a command is used within a printf statement.
Thansk for the help so far!
edit: Just a thought, could I possibly encompass the grep command into a variable and then pipe it into a printf statement?
Last edited by jack.mitchell (2011-01-18 15:50:19)
Offline
Here's an example I use:
[karol@black ~]$ type stopwatch
stopwatch is a function
stopwatch ()
{
zero=$(date "+%s");
echo "Start!";
while true; do
now=$(date "+%s");
time=$(($now - $zero));
printf "\r${time}";
sleep 0.2;
done
}
Just a thought, could I possibly encompass the grep command into a variable and then pipe it into a printf statement?
Yes, exactly :-)
Last edited by karol (2011-01-18 15:57:38)
Offline
Try this
while read p; do echo -en "\rPercent: $(grep -o '[0-9]\+%' <<< $p)"
done < <(wget http://wireless.kernel.org/download/compat-wireless-2.6/compat-wireless-2.6.tar.bz2 2>&1)
echo
Offline
@rockinturtle
That works perfectly, I'll also have a go at implementing your method too karol for practice
Cheers all!
Offline
Pages: 1