简体   繁体   English

如何从另一个shell脚本导入变量?

[英]how to import variable from another shell script?

i have to write a bash script wherein i need to connect with oracle database and perform some queries.我必须编写一个 bash 脚本,其中我需要连接 oracle 数据库并执行一些查询。 `sqlplus $DB_USER/$DB_PASSWORD' These variables are stored in another file "rangerenv.sh" How do i use these variables in another bash file? `sqlplus $DB_USER/$DB_PASSWORD' 这些变量存储在另一个文件“rangerenv.sh”中 我如何在另一个 bash 文件中使用这些变量?

You could extract those values into a separate config file that both scripts can access.您可以将这些值提取到两个脚本都可以访问的单独配置文件中。 Your script can use source load the variables from this file.您的脚本可以使用source加载此文件中的变量。

config file config文件

DB_USER="user"
DB_PASSWORD="password"

your script你的script

source config
sqlplus $DB_USER/$DB_PASSWORD

Be careful mixing sensitive variables with your code as they can end up in source control, backups or other places where they may be exposed to malicious actors.小心将敏感变量与您的代码混合,因为它们最终可能会出现在源代码控制、备份或其他可能暴露给恶意行为者的地方。 If these credentials exist in multiple files it can be difficult to rotate them and keep your database secure.如果这些凭据存在于多个文件中,则很难轮换它们并确保数据库安全。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM