Hi,
I'm trying to write up a little shell script to automate installing vim scripts once I install a new Linux distro on a machine.
This is the general idea:
1. Let user specify vim dir (we would install the scripts in the plugin dir of this vim dir).
2. Let user choose which plugins they want to install from a list of displayed scripts ($choice would hold this choice).
3. wget the script and install it in dir specified in step 1.
I'm having problems with step 3.
This is what I have so far:
Code:
wget -O blah.zip http://www.vim.org/scripts/$(wget -qO - http://www.vim.org/scripts/script.php?script_id=${choice} | cat | grep -m 1 -o download_script\.php\?src_id=[0-9]*)
in the above code, the nested wget would run in quiet (-q) mode and output to STDOUT (-O -), fetching the script selected in step 2.
It would then pipe the output to cat and grep for the first match (-m 1) and only print out the part that matched the expression (-o) which would be the first (i.e. latest) download script for a vim script.
Then, the outer wget would download the matched expression and output to a 'blah.zip' file
My problem is, I don't want to output to blah.zip, I want to output to the relevant named script but I can't capture any matched expressions using grep or egrep.
I've tried the following (only the last part of the grep expression where I match the digits is modified here):
Code:
wget -O blah.zip http://www.vim.org/scripts/$(wget -qO - http://www.vim.org/scripts/script.php?script_id=${choice} | cat | grep -m 1 -o (download_script\.php\?src_id=[0-9]*)\"\>([^\<]*)\</a\>)
But I don't know how to access the captured expression in grep or egrep.
So, for example if I were to install the Rails script for vim which is:
Code:
http://www.vim.org/scripts/script.php?script_id=1567
my script should download to a file called "rails.zip" which would have the following URL as of today:
Code:
http://www.vim.org/scripts/download_script.php?src_id=9854
Any ideas?
Oh also, in my expression, why do I have to use:
Code:
download_script\.php\?src_id=[0-9]*
instead of:
Code:
download_script\.php\?src_id=[0-9]{,4}
Thanks!