本文介绍了如何从变量中删除前导零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试删除bash中变量前面的所有零.但是我无法将其保存在变量中.一些帮助
I am trying to remove all the zeros in front of a variable in bash. But I am not able to save it in the variable. Some help
问题在这里: if((($ line> $ lastMin)));然后
运行Bash错误,因为该值对于基数太大(错误元素为"0455233")
a Bash error run because value too large for the base (the error element is "0455233")
这就是为什么我试图通过删除在我面前发现的所有零来保存该值的原因
That's why I'm trying to save that value by removing all the zeros I find in front of me
请问有什么解决办法吗?
Any solutions please?
lastMin=0455233
zeroMin=$(( $lastMin | sed 's/^0*//' ))
推荐答案
删除所有前导 0
's;
lastMin='0000455233'
zeroMin=$(echo "$lastMin" | sed 's/^0*//')
echo "$zeroMin" # output : 455233
您的问题是由使用 $((而不是
$(
)引起的,而不是使用 echo
'来替换旧变量.
Your problem is caused by using
$((
instead of $(
, and not echo
'ing the old var.
这篇关于如何从变量中删除前导零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!