Here's a one-liner for getting one variable:
MY_VAR=$(grep MY_VAR .env | cut -d '=' -f2)
One issue i see with all these solutions is: what happens if i have two similar variables. I need to fix the Grep part to only match
Also... i would never have thought about using grep here, so Thank You.
If you're having trouble with spaces still messing up your loading of the variables, use this:
Explanation: IFS changes what bash splits strings on. By default it splits on spaces, but using the above it only does so on newlines. We reset its behavior after we're done.