如何隐藏或在我的bash脚本删除零? [英] How to hide or delete the zero in my bash script?
本文介绍了如何隐藏或在我的bash脚本删除零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的脚本:
echo -n "number 1 :";
read bil1
echo -n "number 2 :";
read bil2
multiple=$(echo $bil1*$bil2 |bc -l |sed -e 's/^\./0./' -e 's/^-\./-0./');
echo " Your result : $bil1 * $bil2 = $multiple ";
如果我输入 9.5
为 $ bil1
和 300
为 $ bil2
,结果是 2850.0
。
If I input 9.5
for $bil1
and 300
for $bil2
, the result is 2850.0
.
我想要的结果:
Your result : 9.5 * 300 = 2850
我如何隐藏或结果的末尾加上零?即只显示 2850
?
推荐答案
以下部分添加到您的sed命令(在末尾):
Add the following part to your sed command (at the end):
-e 's/\.0*$//'
(删除一个点,然后在通过没有结束任意多个零)。
(Delete a dot followed by arbitrarily many zeroes at the end by nothing.)
顺便说一句,你最好更换回声$ bil1 * $ bil2
按回声$ bil1 * $ bil2
,否则你可能会根据当前目录的内容得到奇怪的效果。
By the way, you better replace echo $bil1*$bil2
by echo "$bil1*$bil2"
, otherwise you may get strange effects depending on the contents of the current directory.
这篇关于如何隐藏或在我的bash脚本删除零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文