Quoting from man openssl (near the end):
PASS PHRASE ARGUMENTS
Several commands accept password arguments, typically using -passin and -passout for input and output passwords respectively. These allow the password to be obtained from a variety of sources. Both of these options take a single argument whose format is described below. If no password argument is given and a password is required then the user is prompted to enter one: this will typically be read from the current terminal with echoing turned off.
That's followed by a list of possible ways of acquiring the password. I would think that the one you want is stdin, although it might well work out better to use the option for an environment variable. (You'll need to export the variable for that to work.)
I suggest you read the description carefully, taking account of the security implications. You should also read the manpage for the subcommand you are using (enc), or at least read through the summary provided if you specify an option it does not understand.
(In enc, the actual option specified is neither -passin nor -passout but rather -pass.)