I am writing a script where I am trying to export some variable , and after exporting my variable when I am printing, it is printing an extra line after it.
Here I am reading from a csv file containing two columns. This script is present in file script.sh and I am executing that file ./script.sh
#!/bin/bash while IFS="," read f1 f2 do echo "Source IP : $f1" #it is printing without extra line echo "Destination IP : $f2" #it is printing without extra line export sourceIP=$f1 export destIP=$f2 ssh -t -t sjain@$f1 <<ENDSSH #Start copying 33KB File echo "Destination IP Address: $destIP" # here it is printing an extra line after destIP startTime=$(($(date '+%s%N')/1000000)) scp KB_33.txt sjain@$destIP:/home/sjain endTime=$(($(date '+%s%N')/1000000)) printf 'Elapsed time in copying 33KB file: %s\n' $((endTime-startTime)) #Write the stats to the file echo $sourceIP','$destIP',33KB,'$((endTime-startTime)) >> report.txt exit ENDSSH done < ipaddress.csv
because of the above problem when I am executing
scp KB_33.txt sjain@$destIP:/home/sjain
it is breaking the command into 2 parts , like this
scp KB_33.txt sjain@$X.X.X.X :/home/sjain
And when I am directly hardcoding the value instead of destIP , it is working fine.
How can I fix this?
Input CSV file Data