Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running shell script using .env file

Tags:

I am fairly new to running scripts in UNIX/Linux. I have a .env file containing environment information and a .sh script containing folder creations etc for that environment.

How would I run the script on the environment contained in the .env file or how could I point the script to the target environment?

Would it be as easy as:

bash 'scriptname.sh' 'filename.env' 
like image 635
Tony Avatar asked Feb 11 '16 18:02

Tony


1 Answers

You need to source the environment in the calling shell before starting the script:

source 'filename.env' && bash 'scriptname.sh' 

In order to prevent polution of the environment of the calling shell you might run that in a sub shell:

(source 'filename.env' && bash 'scriptname.sh') 
like image 141
hek2mgl Avatar answered Nov 09 '22 17:11

hek2mgl