bash 使用 curl 使用目录中的所有文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23494388/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using all files in a directory with curl?
提问by user1856596
This is my script:
这是我的脚本:
#!/bin/bash
curl -X POST -T /this/is/my/path/system.log https://whatever;
As you see, I am using a file called system.log. How can I do that for the complete /this/is/my/path/ path in a loop? There are about 50 files in /this/is/my/path/ which I want to use with curl.
如您所见,我正在使用一个名为 system.log 的文件。如何在循环中为完整的 /this/is/my/path/ 路径执行此操作?/this/is/my/path/ 中有大约 50 个文件我想与 curl 一起使用。
Thanks!
谢谢!
回答by Brian
You can upload multiple files using this range syntax in curl:
您可以在 curl 中使用此范围语法上传多个文件:
$ curl -u ftpuser:ftppass -T "{file1,file2}" ftp://ftp.testserver.com
回答by Raul Luna
A very robust solution is to iterate through a for loop. Moreover you can take advantage of this and insert echo commands or delete, or whatever command you want.
一个非常健壮的解决方案是遍历 for 循环。此外,您可以利用这一点并插入回显命令或删除,或您想要的任何命令。
#!/bin/bash
for file in /this/is/my/path/*
do
curl -X POST -T "/this/is/my/path/$file" https://whatever;
done; # file