简体   繁体   中英

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:

#!/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:

% 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. 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

export index1_0="a_b_c"

and source it

source first.sh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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