使用 .env 文件运行 shell 脚本 [英] Running shell script using .env file

查看:80
本文介绍了使用 .env 文件运行 shell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对在 UNIX/Linux 中运行脚本相当陌生.我有一个包含环境信息的 .env 文件和一个包含该环境的文件夹创建等的 .sh 脚本.

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.

如何在 .env 文件中包含的环境中运行脚本,或者如何将脚本指向目标环境?

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?

会不会这么简单:

bash 'scriptname.sh' 'filename.env'

推荐答案

启动脚本前需要在调用shell中source环境:

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

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

为了防止调用shell的环境污染,您可以在子shell中运行它:

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')

这篇关于使用 .env 文件运行 shell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆