I needed to remove all the leading zeros in a script, so when I looked this up on line I found this solution that works so perfectly:
bash ~$ cat > Numbers.txt
000943
010000
000002
006500
bash ~$ OldNumbers=`cat Numbers.txt`
bash ~$ let NewNumbers=10#$OldNumbers
bash ~$ echo $NewNumbers > NewNumbers.txt
bash ~$ cat NewNumbers.txt
943
10000
2
6500
bash ~$
Now I have found that this # operator seems to multiply %10 of $OldNumbers by its self. So %10x%10 is %100 percent, thus the numbers stay the same. I have also found that you cannot use any numbers below 10, but you can use numbers above. 20#100 gives you 400. And I have found that I cannot exceed 64. The only connection I can think of is the fact that Mac OS X is 64 bit. Does anyone know what the # Arithmetic Operator does in Bash?
bash ~$ cat > Numbers.txt
000943
010000
000002
006500
bash ~$ OldNumbers=`cat Numbers.txt`
bash ~$ let NewNumbers=10#$OldNumbers
bash ~$ echo $NewNumbers > NewNumbers.txt
bash ~$ cat NewNumbers.txt
943
10000
2
6500
bash ~$
Now I have found that this # operator seems to multiply %10 of $OldNumbers by its self. So %10x%10 is %100 percent, thus the numbers stay the same. I have also found that you cannot use any numbers below 10, but you can use numbers above. 20#100 gives you 400. And I have found that I cannot exceed 64. The only connection I can think of is the fact that Mac OS X is 64 bit. Does anyone know what the # Arithmetic Operator does in Bash?
Last edited: