简体   繁体   English

使用来自 sh 脚本文件的 erb 文件中的变量

[英]Use the variables in erb file from sh script file

I have a script name first.sh and in that I have called few variables like below:我有一个脚本名称first.sh ,其中我调用了几个变量,如下所示:

#!/bin/bash

index1_0="a_b_c"
index2_0="b_c_d"
index3_0="c_d_e"

The script path of first.sh is goal/first.sh .I'm trying to use above variables called in first.sh in another second.erb file like below: first.sh的脚本路径是goal/first.sh 。我正在尝试在另一个second.erb文件中使用上面在 first.sh 中调用的变量,如下所示:

% H = Hash["a" => "@index1_0",
%   "b" => "@index2_0",
%   "d" => "@index3_0",]

I need to use the variables declared in first.sh script file in second.erb file but not getting the exact output.我需要在second.erb文件中使用first.sh脚本文件中声明的变量,但没有得到确切的 output。 Can someone help here?有人可以帮忙吗?

You need你需要

<%= ENV['index1_0'] %>

to access the value of an environment variable that you need to export from first.sh like访问需要从first.sh导出的环境变量的值,例如

export index1_0="a_b_c"

and source it并获取它

source first.sh

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

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