Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading data from properties file in shell script

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 ?

like image 894
charan Avatar asked Sep 10 '13 06:09

charan


1 Answers

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}"
like image 112
devnull Avatar answered Nov 15 '22 08:11

devnull