gpt4 book ai didi

linux - Bash 中的输出格式

转载 作者:行者123 更新时间:2023-12-04 18:39:33 24 4
gpt4 key购买 nike

echo "Station pairs are $station1($code1) and $station2($code2) | distance=$c degrees or `echo $c|awk '{print $1*111.2}'` km"

我在 bash 的“for”循环中运行上述代码。变量“station1”、“code1”、“station2”、“code2”
在循环的每次迭代后都在变化,它给了我这样的输出:
Station pairs are Zhozho2(WT15) and Guoban(WT19) | distance=1.4755108271 degrees or 164.077 km
Station pairs are Zhozho2(WT15) and Yarla(WT20) | distance=1.63208637417 degrees or 181.488 km
Station pairs are Zhozho2(WT15) and Zhungba(ZNBA) | distance=1.28887286927 degrees or 143.323 km
Station pairs are Hill(WT16) and N-Napuk(WT17) | distance=1.22929482902 degrees or 136.698 km
Station pairs are Hill(WT16) and Zhungba(ZNBA) | distance=1.87133807827 degrees or 208.093 km
Station pairs are N-Napuk(WT17) and Barkar(WT18) | distance=1.73933270787 degrees or 193.414 km

如何以我的输出如下所示的方式打印这些行:
Station pairs are Zhozho2(WT15)  and Guoban(WT19)  | distance=1.4755108271   degrees or 164.077 km
Station pairs are Zhozho2(WT15) and Yarla(WT20) | distance=1.63208637417 degrees or 181.488 km
Station pairs are Zhozho2(WT15) and Zhungba(ZNBA) | distance=1.28887286927 degrees or 143.323 km
Station pairs are Hill(WT16) and N-Napuk(WT17) | distance=1.22929482902 degrees or 136.698 km
Station pairs are Hill(WT16) and Zhungba(ZNBA) | distance=1.87133807827 degrees or 208.093 km
Station pairs are N-Napuk(WT17) and Barkar(WT18) | distance=1.73933270787 degrees or 193.414 km

最佳答案

首先将变长字符串放入temp变量,然后使用 printf以格式化方式输出:

temp=$station1($code1)
printf 'Station pairs are %-15s and ...\n' $temp

关于linux - Bash 中的输出格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61890130/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com