如何获得卷曲保存到不同的目录? [英] How to get CURL to save to a different directory?
问题描述
我需要能够在文件下载的URL传递,再加上文件的路径保存到。
I need to be able to pass in the URL of the file download, plus a path for the file to be saved to.
我认为这是与-O和-o上的卷曲,但我似乎无法找到答案。
I think it has something to do with -O and -o on CURL, but I can't seem to figure it out.
例如,这是我使用的是什么在我的bash脚本现在:
For example, this is what I'm using in my bash script now:
#!/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 I can do
getsrc http://www.apache.org/dist/ant/binaries/apache-ant-1.7.1-bin.tar.gz /usr/local
,并将它保存文件到/ usr /地方?
and have it save the file to /usr/local?
推荐答案
呜呜......你可能想要做的就是
Hum... what you probably want to do is
getsrc(){
( cd $2 > /dev/null ; curl -O $1 ; )
}
该-O(资本的O)说要存储在本地命名,如远程文件,但忽略了远程路径组件。为了能够在一个特定的目录来存储,最简单的办法是cd到它...而我呢,在一个子shell,所以DIR变化不会传播
The -O (capital O) says to store in a local named like the remote file, but to ignore the remote path component. To be able to store in a specific directory, the easiest way is to cd to it... and I do that in a sub-shell, so the dir change does not propagate
这篇关于如何获得卷曲保存到不同的目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!