How do you want to use the generated key?
You say it is a secret key, but looks like anyone can see it…
You could simply store the key into a file and use it from there.
Something like this:
# file for storing the key
touch /home/your-account/.secret-key # change your-account to your username
# create and store the key
openssl rand -hex 32 > /home/your-account/.secret-key
# use the key somewhere
That’s a useless use of cat – you’re launching a separate program from your script just to get the contents of a file into a variable. In fact, there is almost never any need to use cat in a Bash script, as Bash provides facilities for that.
Don’t do that… Do this instead:
Indeed. The OP might want to consider the security implications of that. Depending on the use case, it may or may not be a good idea.