user892960
user892960

Reputation: 309

how to disable variable expansion when using bash "eval"

hi I have following propertie file (something.properties)

SERVER1_PROPERTY1=123    
SERVER1_PROPERTY2=${SERVER1_PROPERTY1}/123

and following bash script fetching one of the properties:

#!/bin/bash

. something.properties

SRV="SERVER1"

eval PROPERTY2=\$${SRV}_PROPERTY2

echo $PROPERTY2

the result is:

123/123

but I want it to be

${SERVER1_PROPERTY1}/123

How can I achieve this?

Upvotes: 0

Views: 2242

Answers (1)

Arnaud Le Blanc
Arnaud Le Blanc

Reputation: 99889

The expansion is done when you source the file (. something.properties).

Write SERVER1_PROPERTY2='${SERVER1_PROPERTY1}/123' in your properties files to disable expansion.

Upvotes: 1

Related Questions