Question

I am writing a shell script which reads data from a properties file and stores in into a local variable in shell script. The problem is when i am trying to read multiple properties from the file and form a string its getting over written

#!/bin/bash
. /opt/oracle/scripts/user.properties

echo $username
echo $password
echo $service_name

conn=$username$password$service_name
echo $conn

the values of username=xxxx password=yyyy and service_name=zzzz i expect the output to be

xxxxyyyyzzzz 

but instead of that i am getting the output as

zzzz

please tell me where am i doing the mistake ?

Was it helpful?

Solution

I'm certain that the file /opt/oracle/scripts/user.properties contains CR+LF line endings. (Running the file command for the properties file would say ... with CRLF line terminators). Changing those to LF using dos2unix or any other utility should make it work.

Moreover, instead of saying:

conn=$username$password$service_name

you could say:

conn="${username}${password}${service_name}"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top