Bash: Read Variables from Text-File VAR=VALUE Form

2019-07-23 21:29发布

问题:

I want to load some variable from a text file into my batch script. I tried searching but I only find tips for files like

VALUE1
VALUE2
...

My TEXT-File has the following format:

VER=123
MIN_VER=123456789
TARGET_VER=132456790

And I want to be able to load this file so that I can access the three variables for matching it against a number in bash. How can I achieve this?


Answered! Thanks!

回答1:

Save your variables to file like you want (VAR=VAL) and run:

. ./your_file

Maybe there will have to be"#!/bin/bash" at the beginning of this file. False