Reputation: 71
I have the below shell script. Please help me to understand why the values of $mft_dir and $mft_dir1 are different?
SCRIPT(test.sh)
#! /bin/sh
######## Reading properties file
function getProperty {
awk -F'=' -v k="$1" '$1==k&&sub(/^[^=]*=/,"")' $ENVIRONMENTROOT/properties/ExtServerConnection.properties
}
key=$2
######################## LOCAL Server Details ##########################
########MFT path
mft_dir=$(getProperty "${key}_mft_dir")
mft_dir1="/sjcqa01/exec/ENVIRONMENTROOT/EAIDATA/Inbound/MFT/EXL"
echo $mft_dir
echo $mft_dir1
if [ "$mft_dir" != "$mft_dir1" ] ; then
echo "Not equal"
fi
echo "------------------ END OF THE SCRIPT ---------------------"
Properties File Entry
XYZ_mft_dir=/sjcqa01/exec/ENVIRONMENTROOT/EAIDATA/Inbound/MFT/EXL
Execution Command
./test.sh -key XYZ
Output
/Inbound/MFT
/Inbound/MFT
Not equal
Upvotes: 0
Views: 123
Reputation: 71
I used the following sed command to strip off the carriage return and my issue got resolved:
sed -e 's/\r//g'
Upvotes: 0
Reputation: 8621
Replace your #! /bin/sh
line with #!/bin/bash
.
I did that with your code and it worked perfectly.
./so.bash -key XYZ
>>/sjcqa01/exec/ENVIRONMENTROOT/EAIDATA/Inbound/MFT/EXL<<
>>/sjcqa01/exec/ENVIRONMENTROOT/EAIDATA/Inbound/MFT/EXL<<
------------------ END OF THE SCRIPT ---------------------
Note I added >>
and <<
characters to see the exact output of the echo commands.
Note2: some systems might require #!/usr/bin/bash
. Adjust according to your system (which bash
will show you where it is).
Note3: do not put a space between #!
and your shell path.
Note4: well done using $()
and not backticks :-)
Upvotes: 1