Removing leading zeros before passing a shell variable to another command

前端 未结 14 1248
长情又很酷
长情又很酷 2020-12-08 18:52

It turns out that iptables doesn\'t handle leading zeros too well. As $machinenumber that is used has to have a leading zero in it for other purposes, the idea

14条回答
  •  伪装坚强ぢ
    2020-12-08 19:19

    Using sed:

    echo 000498 | sed "s/^0*\([1-9]\)/\1/;s/^0*$/0/"
    498
    echo 000 | sed "s/^0*\([1-9]\)/\1/;s/^0*$/0/"
    0
    

提交回复
热议问题