Search code examples
bashstring-concatenationcommand-substitution

Shell sha1($salt.$password) error


I try to do something like this directly on my console as some testruns :

It does not seem to work.. any idea what is the mistake I am doing

salt="3245678906789045689"
password="12321312231"
blub=`sha1($salt.$password)`
-bash: command substitution: line 1: syntax error near unexpected token `$salt.$password'
-bash: command substitution: line 1: `sha1($salt.$password)'

It throws out an errors this is what I intend to do at the end:

echo $blub

Can some one please helpout as to what is the error I am doing?


Solution

  • Probably you want to use SHA1 from the OpenSSL package. This should be already installed on your system.

    echo -n "$salt$password" | openssl dgst -sha1
    (stdin)= a1b2ce5a82e18f454db6b2d6ee82533914f90337
    

    To capture just the sha1-digest:

    blub=`echo -n "$salt$password" | openssl dgst -sha1 |awk '{print $NF}'`
    echo $blub
    a1b2ce5a82e18f454db6b2d6ee82533914f90337
    

    I assume you copied your code from PHP. There functions are called with brackets and the .-Operator concatenates strings. In that interpretation my code is the exact equivalent of your code in BASH.