bash 将 curl 与命令文件一起使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8829167/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 01:17:10  来源:igfitidea点击:

Use curl with a file of commands

bashcurl

提问by John Livermore

I am using curl from a BASH shell. I would like to create a text file of commands to send via curl and then somehow have all of them run at once. It's been a long time since I dealt with UNIX commands, but can someone show me how to accomplish this please (assuming I have a file created called commands.txt)?

我正在使用 BASH shell 中的 curl。我想创建一个命令文本文件,通过 curl 发送,然后以某种方式让所有命令同时运行。自从我处理 UNIX 命令以来已经很长时间了,但是有人可以告诉我如何完成此操作吗(假设我创建了一个名为 commands.txt 的文件)?

Editing this post to include an example of the file of commands I would like to execute in batch...

编辑这篇文章以包含我想批量执行的命令文件的示例...

curl -XPUT 'http://localhost:9200/foo/property/1' -d '{"firstName":"Domino","lastName":"Derval"}'
curl -XPUT 'http://localhost:9200/foo/property/2' -d '{"firstName":"Elektra","lastName":"King"}'
curl -XPUT 'http://localhost:9200/foo/property/3' -d '{"firstName":"Fiona","lastName":"Volpe"}'
curl -XPUT 'http://localhost:9200/foo/property/4' -d '{"firstName":"Holly","lastName":"Goodhead"}'
curl -XPUT 'http://localhost:9200/foo/property/5' -d '{"firstName":"Honey","lastName":"Rider"}'
curl -XPUT 'http://localhost:9200/foo/property/6' -d '{"firstName":"Jill","lastName":"Masterton"}'
curl -XPUT 'http://localhost:9200/foo/property/7' -d '{"firstName":"Kissy","lastName":"Suzuki"}'
curl -XPUT 'http://localhost:9200/foo/property/8' -d '{"firstName":"Mary","lastName":"Goodnight"}'
curl -XPUT 'http://localhost:9200/foo/property/9' -d '{"firstName":"Miranda","lastName":"Frost"}'
curl -XPUT 'http://localhost:9200/foo/property/10' -d '{"firstName":"Molly","lastName":"Warmflash"}'
curl -XPUT 'http://localhost:9200/foo/property/11' -d '{"firstName":"Paula","lastName":"Caplan"}'
curl -XPUT 'http://localhost:9200/foo/property/12' -d '{"firstName":"Penelope","lastName":"Smallbone"}'
curl -XPUT 'http://localhost:9200/foo/property/13' -d '{"firstName":"Pussy","lastName":"Galore"}'
curl -XPUT 'http://localhost:9200/foo/property/14' -d '{"firstName":"Strawberry","lastName":"Fields"}'
curl -XPUT 'http://localhost:9200/foo/property/15' -d '{"firstName":"Sylvia","lastName":"Trench"}'
curl -XPUT 'http://localhost:9200/foo/property/16' -d '{"firstName":"Tatiana","lastName":"Romanova"}'
curl -XPUT 'http://localhost:9200/foo/property/17' -d '{"firstName":"Tilly","lastName":"Masterton"}'
curl -XPUT 'http://localhost:9200/foo/property/18' -d '{"firstName":"Vesper","lastName":"Lynd"}'
curl -XPUT 'http://localhost:9200/foo/property/19' -d '{"firstName":"Xenia","lastName":"Onatopp"}'

回答by kev

create a script download.sh

创建脚本 download.sh

#!/bin/bash    
# put all your commands here
curl ...
.
.
.
curl ...

make download.shexecutable

使download.sh可执行

$ chmod +x download.sh

run donwload.sh

donwload.sh

$ ./download.sh