在bash中的命令之前添加文本 COLUMNS=$(tput cols) weather=“Temperature${IFS}”$(weather.txt printf“%*s\n”$((${{weather}+$COLUMNS)/2))$weather | pv-ql80

在bash中的命令之前添加文本 COLUMNS=$(tput cols) weather=“Temperature${IFS}”$(weather.txt printf“%*s\n”$((${{weather}+$COLUMNS)/2))$weather | pv-ql80,bash,Bash,所需输出:[温度为(温度)] 我做错了什么?您在最后一行中没有引用$weather,所以printf的两个参数是温度和+34°F 这应该起作用: COLUMNS=$(tput cols) weather="Temperature${IFS}"$(<weather) curl -s 'wttr.in/Boston?format=%t' > weather.txt printf " %*s\n" $(((${#weather}+$COLUMNS)/

所需输出:
[温度为(温度)]


我做错了什么?

您在最后一行中没有引用
$weather
,所以printf的两个参数是
温度
+34°F

这应该起作用:

COLUMNS=$(tput cols)
weather="Temperature${IFS}"$(<weather)
curl -s 'wttr.in/Boston?format=%t' > weather.txt
printf " %*s\n" $(((${#weather}+$COLUMNS)/2)) $weather | pv -qL 80


echo“[温度为$(curl-s'wttr.in/Boston?format=%t')”
?是根据
$(${weather}+$列)/2)计算得出的温度$weather
?@ChritopherMoore:你忘了输出单词Temperature is…你能显示你的实际输出吗?printf:+34°F:无效数字Temperature非常感谢你花时间!有没有办法删除度符号?如果你只想替换度符号请尝试
“${weather/°}”
。如果您想删除学位符号后的所有内容,也可以尝试
“${weather/°*}”
。哇。非常感谢您,现在它不在中心了。。。。
printf " %*s\n" $(((${#weather}+$COLUMNS)/2)) "$weather" | pv -qL 80