I know that is a duplicate question from here : Link
I tried to do a little more research into if its possible or no at-all.
and I see that it is possible.
The only thing I want to get is what is the function that I need to use to convert a string to an integer in shell scripting. SHA1 is a 160bit long integer.
Motivation behind doing it on shell scripting : trying to learning it.
For example I get the sha1 of a file by storing it in a variable like this
store=`sha1 $blah | cut -d ' ' -f 1`
it gives me the hash . But what if I want to convert it to integer.
Impossible. For the shell, everything is a string. If you leave POSIX, and declare shell variables as having integer type, the width of the integer is usually that of the underlying C library, i.e. 32 or 64 bit. SHA1 hashes with 160bits don’t fit.
However, there are the
bcanddcutilities, which allow arbitrary precision arithmetic.If you just want to convert the hex string to a decimal number, use this:
Note that you MUST USE CAPITAL HEX DIGITS, because
bcwon’t recognize a-f.