0

I'm working on a function that checks if certain packages are installed and prefers own builds, which paths are stored in a config file.

So the function get's an input like

rsync

It then proceeds to form a new variable called

$bin_variable_name

which has the value

RSYNC_BIN

In the config-file mentioned above could be a line like this.

RSYNC_BIN="/home/<username>/Software/rsync"

So if this file is sourced at the beginning of the function, the variable $RSYNC_BIN has a value other than ''.

I now need to check this in an if-statement. Unfortunately I cannot reference $RSYNC_BIN directly since the function should work with any given input. So I somehow need to "evaluate"

$bin_variable_name

inside the if-statement, so that bash doesn't executes

if [[ $bin_variable_name == '' ]]; then ...

but rather

if [[ $<whatever comes from $bin_variable_name>_BIN = '' ]]; then ...

Is this even possible?

Thanks in regards.

1 Answer 1

3

With indirection

$ bin_variable_name=RSYNC_BIN
$ RSYNC_BIN="/home/<username>/Software/rsync"
$ echo "${!bin_variable_name}"
/home/<username>/Software/rsync

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .