0

I have this code:

#!/bin/ksh

value=''
builddir=`dirname $0`
cd $builddir
while read line 
do
    echo line: $line
    param=`echo $line|cut -d '=' -f1`
    if [[ $param = 'profile.home' ]] 
    then
        value=`echo $line|cut -d '=' -f2`
        echo was_profile:$value
        break
    fi
done < was-config.properties
if [[ $value = '' ]]
then
    echo "Please configure the profile.home dir into the was.config.properties file and run again the script"
else
  "$value"/bin/ws_ant.sh -buildfile $builddir/build.xml $@

fi

Which returns:

line: #was configuration properties
line: 
line: was.home=/opt/IBM/WebSphere/AppServer/
line: profile.home=/opt/IBM/WebSphere/AppServer/profiles/AppSrv01
was_profile:/opt/IBM/WebSphere/AppServer/profiles/AppSrv01
/bin/ws_ant.sh: not foundBM/WebSphere/AppServer/profiles/AppSrv01

why do I receive a not found? It seems the concatenation "$value"/bin/ws_ant.sh is not working!!!

oguz ismail
  • 1
  • 16
  • 47
  • 69
  • Is ypur properties file ending with ^M from windows? The path `.../AppSrv01^M/bin...` is invalid. – Walter A Apr 04 '20 at 15:44
  • @WalterA that’s a good tip , I will check ASAP – João Pedro Alexandre Apr 05 '20 at 16:10
  • I do not see any ^M in the file, but it is possible that some strange character is interfering with my code. I have tried : echo WAS_HOME: $value##### and the output is: #####OME:/opt/IBM/WebSphere/AppServer/profiles/AppSrv01 It inserts the ##### overriding the value read from the file. – João Pedro Alexandre Apr 06 '20 at 17:46

1 Answers1

0

There are carriage returns (0A or ^M or \r) in your file, see How to convert DOS/Windows newline (CRLF) to Unix newline (LF) in a Bash script?.
In your case you do not need to loop through the config file. You can use

value=$(grep profile.home= was-config.properties | cut -d= -f2 | tr -d '\r')

or

value=$(sed -rn 's/^profile.home=([^\r]*)*/\1/p' was-config.properties)

or

value=$(awk -F "\r|=" '/^profile.home/ {print $2}' was-config.properties)
Walter A
  • 19,067
  • 2
  • 23
  • 43