kzpm
kzpm

Reputation: 133

Pass contents of sha256sum from user input into a variable

I'm having trouble putting the contents of sha256sum from user input into a variable:

echo "Your password please"

read -e pass

pass256=${pass | sha256sum}

printf "Password SHA256 is "$pass256"\n\n"

exit

After execution the script says:

./password_hashing: line 12: ${pass | sha256sum}: bad substitution

I have tried to enclose the complete command between parentheses, without curly_brackets, between single quotes.

Upvotes: 0

Views: 295

Answers (1)

Paul Hodges
Paul Hodges

Reputation: 15418

Try

pass256=$(sha256sum<<<"$pass")

or if you don't want the trailing *-,

read pass256 _ <<< $(sha256sum<<<"$pass")

Upvotes: 1

Related Questions