0

I have an app which runs and reads 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!

1
  • Only if the environment variable LOG_FILE_PATH is declared before that line in the config file. There could be something like delayed expansion, too. But I'm not aware of it and it would depend on your exact shell, which you haven't stated. Commented Apr 19, 2011 at 12:36

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.