Ludo06
Ludo06

Reputation: 11

Problem with concatenating a variable, result of a cat and cut command

I have a bash script in which I read a file .properties and I get a property that I store in a variable:

PROP_VALUE=`cat $PROP_FILE | grep "^$PROP_KEY" | cut -f2 -d'='`

This variable is set to 5.0.1.

When I want to use this variable and concatenate it to a second variable, I get the following result:

CONCAT=".0"
echo $PROP_VALUE
=> Result : 5.0.1

echo $PROP_VALUE$CONCAT
=> Result : .00.1

This removes the first 2 characters of my first variable ($ PROP_VALUE) and replaces them with the characters of my second variable ($ CONCAT).

The expected result is: 5.0.1.0

Upvotes: 0

Views: 370

Answers (2)

Ensure that your .properties is a real unix file. If it is, then your script is ok. If .properties has DOS/winslows encoding, then you are in trouble. There is no other explanation, I think.

Upvotes: 3

Ludo06
Ludo06

Reputation: 11

My property file :

version=5.0.1
category=dev
env=rct

When I use the following syntax I have the same problem :

PROP_VALUE=$(cat $PROP_FILE | grep "^$PROP_KEY" | cut -f2 -d'=')

If $PROP_VALUE is a variable that I created manually (without going to retrieve the value in my property file), it works :

PROP_VALUE="5.0.1"
CONCAT=".0"
echo $PROP_VALUE$CONCAT
=> Result : 5.0.1.0

Upvotes: 0

Related Questions