How to get curl to save to another directory?

I need to be able to pass the file download URL as well as the path to save the file.

I think this has something to do with -O and -o in CURL, but I can't figure it out.

For example, this is what I use now in a bash script:

#!/bin/sh

getsrc(){
    curl -O $1
}

getsrc http://www.apache.org/dist/ant/binaries/apache-ant-1.7.1-bin.tar.gz

How can I change the curl statement so that I can do

getsrc http://www.apache.org/dist/ant/binaries/apache-ant-1.7.1-bin.tar.gz /usr/local

and save the file to / usr / local?

+5
source share
2 answers

Hum ... what you probably want to do is

getsrc(){
    ( cd $2 > /dev/null ; curl -O $1 ; ) 
}

-O (capital O) , . , cd ... -, dir

+6

script, , :

getsrc() {
    ( cd "$2" && curl -O "$1" )
}

, , , , , , ..

&& cd curl , ( , curl , !)

:

  • URL- , .
  • PATH, ( , URL)

, , :

getsrc() {
    curl "$1" > "$2"
}
+6