Joined January 2015
·

Jesus Ramirez

Greater Chicago Area
·

If I run the following at the bash promt:</p>
$ var="00087" $ newvar=${var##+(0)} $ echo $newvar </pre> </code> The results are as expected. The leading zeros are removed. However, once I put this in a script; it does not work. It does not remove the leading zeros. The shopt commands returns extglob on. I'm confused. </p> Now, look at this script:</p>

var="00087"

This works but if value of var=087 then it does not, that would yield 087

newvar=${var##0*0}
echo $newvar
<br>

This one works great as long as there are no zeros at the end

because a value like 320, 10, 50 200 would yields a blank.

var="8700"

newvar=${var##*0}
echo $newvar // yields: a blank
</code>
</pre>

This works as long as there are no zeros at the end. Well, that is not good either. Now what do I do? I guess I use sed.</p>

Achievements
1 Karma
0 Total ProTip Views