Convert string into integer in bash script - “Leading Zero” number error

前端 未结 8 443
情深已故
情深已故 2020-12-12 20:43

In a text file, test.txt, I have the next information:

sl-gs5 desconnected Wed Oct 10 08:00:01 EDT 2012 1001

I want to extract the hour of

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-12 21:29

    The leading 0 is leading to bash trying to interpret your number as an octal number, but octal numbers are 0-7, and 8 is thus an invalid token.

    If I were you, I would add some logic to remove a leading 0, add one, and re-add the leading 0 if the result is < 10.

提交回复
热议问题