我有很多 Json 文件需要发布到curl。那么如何编写相同的循环呢?我正在尝试这种方式
for FILES in $~/network_map_ingestion/networkmap/data/consolidation
ls NetworkMap-*.json;
do
echo $file
#curl -X POST --data @$file -H "Content-Type:application/json" http://10.00.00.0000000/ingestion/entities/wsr/scp/ekl
答案1
您需要循环遍历所有文件。你不需要ls
,只需使用 shell 通配:
for file in ~/network_map_ingestion/networkmap/data/consolidation/NetworkMap-*.json
do
printf 'Processing "%s"\n' "$file"
curl -X POST --data @"$file" -H 'Content-Type: application/json' \
'http://10.00.00.0000000/ingestion/entities/wsr/scp/ekl'
done
随着 的最新版本的发布curl
,这可能会缩短为
for file in ~/network_map_ingestion/networkmap/data/consolidation/NetworkMap-*.json
do
printf 'Processing "%s"\n' "$file"
curl --json @"$file" 'http://10.00.00.0000000/ingestion/entities/wsr/scp/ekl'
done