2

I've I need to automate the creation of sha512 hash. I'm fairly new to bash scripting and none of the things I've read have helped me much.

This line gives me the correct hash and assigns nothing to $hashed

echo -n thingToHash | openssl dgst -sha512 -out $hashed;

This line gives me the wrong hash and also assigns nothing to $hashed

$hashed= thingToHash | openssl dgst -sha512;

I've tried several other things with similar results.

Josh
  • 107
  • 2
  • 9

1 Answers1

1

To assign to a variable: var=$(app_a | app_b)

The dollar sign is used only to read the value.

In your case:

hashed=$(echo "blah" | openssl dgst -sha512)

Then to read the value of the hash:

echo $hashed

Asblarf
  • 483
  • 1
  • 4
  • 14