简体   繁体   English

从配置文件中的Shell脚本读取变量

[英]Read variable from a shell script in config file

I have a shell script in which i have defined some variables like 我有一个shell脚本,其中定义了一些变量,例如

Shell script.sh xyz /abc/def/cde

usecase=${1}
CONFIGDIR=${2}

And I have a config file in which i want to take these variables 我有一个配置文件,我想在其中使用这些变量

config file

USECASE=${usecase}
CONFIG=${CONFIGDIR}

Can you help me how to take the variable from the shell script to config file. 您能帮助我如何将Shell脚本中的变量转换为配置文件吗? I am thinking to use "source" command. 我正在考虑使用“源”命令。 I am not sure if that help. 我不确定是否有帮助。 Can anyone point me to the right direction? 谁能指出我正确的方向?

You can do it with given commands in shell script 您可以使用shell脚本中的给定命令来完成此操作

usecase=${1}
CONFIGDIR=${2}
key1="USECASE="
key2="CONFIG="
echo $key1$usecase >> /path/to/your/config/file
echo $key2$CONFIGDIR >> /path/to/your/config/file

Make sure to replace "/path/to/your/config/file" with path of your config file 确保将“ / path / to / your / config / file”替换为配置文件的路径

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

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