Given I would like create environment variables from files containing newlines and special characters. The clue is that this content can have references to other environment variables which have to be intepreted. Maybe I need more complex tools than just plain bash?
A testfile "testfile.txt" could look like:
* foo
\/-!~
FOO=${FOOBAR}
What I have managed myself so far is the following:
#!/bin/bash
FOOBAR="SUCCESS"
file="testfile.txt"
var_name="TEST"
name="$file"
content="$(<$file)"
echo "$content"
Which gives me a context variable as output (so, exactly the contents of the file):
* foo
\/-!~
FOO=${FOOBAR}
But, how can I:
- Let ${FOOBAR} be set to "SUCCESS" as defined above but do not touch the rest?
- Set an environment variable TEST which would have content as (1)?