[英]echo overwites beginning of line in a bash script
I'm trying to formulate curl requests (echo just for a check) based on variables I got from another curl query我正在尝试根据我从另一个 curl 查询中获得的变量来制定 curl 请求(仅用于检查的回显)
My first curl query result assigned to $invno_list variable is我分配给 $invno_list 变量的第一个 curl 查询结果是
,result,table,invno,latitude,longitude
,_result,0,16734,44.6707726,15.2820759
,_result,0,16768,44.7376213,15.2164268
,_result,0,18061,44.6654625,14.6602612
my script is here我的脚本在这里
declare -i line_number=0
for inv_line in $(echo "$invno_list" | awk -F'\\\\r\\\\n' '{print}');do
line_size=${#inv_line}
if [ ! $line_number -eq 0 ] && [ $line_size -gt 1 ] #avoiding header line and empty line (last)
then
invno=$(echo "$inv_line" | awk 'BEGIN{FS=","}{print $4}')
lat=$(echo "$inv_line" | awk 'BEGIN{FS=","}{print $5}')
lon=$(echo "$inv_line" | awk 'BEGIN{FS=","}{print $6}')
echo "invno is ${invno} lat is ${lat} and lon is ${lon}" #checking variables
echo "curl -X GET -k -i \"${ownURL}?lat=$lat&lon=${lon}&units=metric\""
fi
line_number=$line_number+1
done
The result of this run is这次运行的结果是
invno is 16734 lat is 44.6707726 and lon is 15.2820759
&units=metric" -i "https://api.openweathermap.org/data/2.5/onecall?lat=44.6707726&lon=15.2820759
invno is 16768 lat is 44.7376213 and lon is 15.2164268
&units=metric" -i "https://api.openweathermap.org/data/2.5/onecall?lat=44.7376213&lon=15.2164268
invno is 18061 lat is 44.6654625 and lon is 14.6602612
&units=metric" -i "https://api.openweathermap.org/data/2.5/onecall?lat=44.6654625&lon=14.6602612
I would expect results to be following type我希望结果是以下类型
invno is 40336 lat is 44.6777115 and lon is 15.2872734
curl -X GET -k -i "https://api.openweathermap.org/data/2.5/onecall?lat=44.6777115&lon=15.2872734&units=metric"
Can someone please suggest me what is wrong有人可以建议我有什么问题吗
Look like Shawn was right there were \\r sign who messed up everything看起来肖恩是对的,\\r 标志把一切都搞砸了
This line fixed that这条线修复了
$(echo "$invno_list" | awk '{sub(/\r/,"",$NF); print}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.