I have an script that will read a csv then find a line and concatenate the result into a string. I have my script working fine when executing locally via git bash, but when executing same code on bitbucket it is adding some carriage that I am not been able to remove. This is very frustrating because I'm stuck for several days with this.
Here is the bash script :
function getTestClassLst(){
file="apex-cls-map.csv"
while IFS="," read -r col_clsname col_clsList
do
if [[ $col_clsname == $1 ]];
then
textsize=$(expr length $col_clsList)
if [[ $textsize -gt 1 ]];
then
unitclsLst=$(echo "$col_clsList" | sed "s/.cls//g")
fi
fi
done < <(tail -n +2 $file)
}
function getTstForClassFromCommit(){
clsLst=""
unitclsLst=""
while read line; do
#filter only for classes
if [[ $line == *.cls ]];
then
clsname=${line#*classes/}
getTestClassLst $clsname
echo "## test class : $unitclsLst"
fi
#filter for trigger
if [[ $line == *.trigger ]];
then
triggername=${line#*triggers/}
getTestClassLst $triggername
echo "## test class for trigger : $unitclsLst"
fi
#check if matched found (not empty)
if [ ! -z "$unitclsLst" ];
then
#check if test class not already included
if [[ $clsLst != *$unitclsLst* ]];
then
clsLst+="$unitclsLst,"
echo "## list : $clsLst"
fi
fi
done < cpath.txt
#remove last char which is a ,
cl=${clsLst%?}
#remove " from string for those with multiple test class for one class
echo "## TEST_CLS_LST = $cl" | sed 's/\"//g'
}
The getTestClassLst function loop through a csv an return a column value in that csv The getTstForClassFromCommit function loop through a text file with a list of filename to search within the csv.
When running in git bash locally I get this :
## test class : User_DMN_TEST
## list : User_DMN_TEST,
## test class for trigger : DocuSignStatus_DMN_TST
## list : User_DMN_TEST,DocuSignStatus_DMN_TST,
## test class for trigger : DocuSignStatus_DMN_TST
## TEST_CLS_LST = User_DMN_TEST,DocuSignStatus_DMN_TST
When running via pipeline, I get this :
## test class : User_DMN_TEST
## list : User_DMN_TEST
,
## test class for trigger : DocuSignStatus_DMN_TST
## list : User_DMN_TEST
,DocuSignStatus_DMN_TST
,
## test class for trigger : DocuSignStatus_DMN_TST
## TEST_CLS_LST = User_DMN_TEST
,DocuSignStatus_DMN_TST
I tried different ways to replace the carriage using following codes, but none is working :
echo "## TEST_CLS_LST = $cl" | sed -e 's/\"//g' -e 's/\n//g'
echo "## TEST_CLS_LST = $cl" | sed -e 's/\"//g' -e 's/\\n//g'
echo $(tr -d '\n' < testCls.lst) #where I store the string into a file then replace and display
#store the string in an array then replace array delimeter with , and display the text
IFS=',';echo "${arrayOfCls[*]}";IFS=$' \t\n'