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

查看:323
本文介绍了使用.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中提供环境的源代码:

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

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

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