View Single Post
Posts: 244 | Thanked: 354 times | Joined on Jul 2010 @ Scotland
#6
Following on from Nicolai's explanation - an alternative to using bc is to force bash to interpret the value as decimal, thus having the added option of the leading zero being chopped:

Code:
#!/bin/bash

LIFE=042

# Will return 34 as LIFE is interpreted as octal
echo $((LIFE))

# Force decimal representation
LIFE=$((10#${LIFE}))

# Should return the proper meaning of life 
echo $((LIFE))
 

The Following 7 Users Say Thank You to gregoranderson For This Useful Post: