bash - 在while循环外读取变量
问题描述
我想在while..循环之外读取一个IP(变量)来定位它们。
问题是将结果存储在“STORE_LOCATION”中,然后在循环后调用它:
STORE_LOCATION=''
echo -e "$SUS_IP" | "$AWK" '{ print $2 }' |\
while read -r IP
do
#echo "IP $IP"
STORE_LOCATION+=$( "$CURL" https://ipinfo.io/"$IP" )
done
echo "$STORE_LOCATION"
预期结果是:
{
"ip": "XXX.XXX.XXX.XXX",
"city": "Seattle",
"region": "Washington",
"country": "US",
"loc": "47,-11",
"org": "Inc.",
"postal": "889988",
"timezone": "America/Los_Angeles",
"readme": "https://ipinfo.io/missingauth"
}
{
"ip": "YYY.YYY.YYY.YYY",
"hostname": "HOST",
"city": "Roubaix",
"region": "Hauts-de-France",
"country": "FR",
"loc": "50,3",
"org": "SAS",
"postal": "59100",
"timezone": "Europe/Paris",
"readme": "https://ipinfo.io/missingauth"
}
提前致谢
解决方案
推荐阅读
- android - 奇怪的 AndroidViewModel LiveData 观察者行为
- kotlin - 如何捕获被拒绝的承诺并继续使用 kovenant 进行承诺更改
- laravel - 在 Hostinger 上部署 Laravel 项目
- c# - 如何用共享路径中的单个反斜杠替换双反斜杠
- python - 如何将购买 DataFrame 转换为 Spark DistributedMatrix 类型以计算项目之间的相似性?
- maven - Maven 原型:生成强制 groupId 作为包结构
- c++ - g ++ c ++ 17类模板参数推导在非常特定的情况下不起作用
- python - 如何将图像分析结果添加到 python 中的数据框中(对于混淆矩阵)?
- r - R Shiny 可以用于导入文件、运行 R 脚本和导出文件吗?
- spring-boot - s3 入站通道适配器中的本地目录表达式