Read / Run Environment Variables in a text file
I have an app which runs and re开发者_Python百科ads a text configuration file. This points to several locations of configurations / outputs etc.
Is it possible to use environmental variables inside the text configuration file, rather than hardcoded paths?
LogFilePath=$LOG_FILE_PATH vs LogFilePath=/home/user/logs
When running, the application fails as it cannot expand the Environment Variable. It will be sourced inside the shell before the application is run.
Thanks!
Recently I used this in a (bash
) script:
#!/bin/bash
# ...
source config.file
# ...
Where config.file
had lines like this:
export ORIG_PATH="${PATH:-.}:/bla/bla"
export SOMESETTING="${SOMEVAR:-"somedefault"},somedata"
...
So the ${parameter:-word}
thing worked well for me: use default values, if parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted. (From man bash
.)
HTH
精彩评论