0

I have ini file(env_var.ini) like below

[regionA]
export PROJECT_ID=123
export PROJECT_NAME="project1"

[regionB]
export PROJECT_ID=234
export PROJECT_NAME="project2"

First i want to set env variables(project_id,project_name) which is in regionA, after the completion of some operation , i need to set env variables which is in regionB. How i can achieve this using array or loop something.

Jega B
  • 35
  • 2
  • 12

1 Answers1

0

source <file_name> will set the variables, but you'll probably need to split the original file, so that it will contain only the block you need;

You can use csplit; for instance:

csplit <file_name> 4 (will split the file into two files in line 4)

now use:

source <file_name_1>

and then:

source <file_name_2>

Here's the IBM csplit tutorial...

Goodluck!

Naor Bar
  • 1,991
  • 20
  • 17
  • I don't understand the downvote. The answer could have more text (how to use csplit with pattern `[...]` without giving a link) and a warning about the ini-file layout (example layout is OK, don't use spaces around the `=` and use quotes). Even without these changes the answer is nice, so upvoted by me. – Walter A Dec 09 '18 at 16:45
  • How should OP loop through the regions using these ingredients? – Walter A Dec 09 '18 at 16:48