I have a file set_env.sh, that I run in the terminal using:
sh set_env.sh
The code runs, but the variables are not set. I am checking with
echo $EMAIL_SERVER
set_env.sh
#!/bin/sh
echo email Address
read y
echo email password?
read x
export EMAIL_SERVER='smtp.gmail.com'
export EMAIL_PORT=587
export EMAIL_DOMAIN='domain.com'
export EMAIL_AUTHENTICATION='plain'
export EMAIL_ENABLE_STARTTLS_AUTO=true
export EMAIL_USERNAME=$y
export EMAIL_PASSWORD=$x
Use
source
command instead:The command executes the script in the current shell context as opposed to invocation via separate shell process:
sh set_env.sh
(the environment variables are set within the newsh
process which is isolated from the current process).By the way, you can use dot (
.
) instead ofsource
, if you prefer.