I have this simple script:
#!/usr/bin/ksh
while read param1 param2
do
echo "Parameter1: $param1 - 1"
echo "Parameter2: $param2 - 2"
done <<< "$(list.ksh)"
The script list.ksh calls a Java servlet and then returns a list of servers in this style:
192.168.1.1 server1
192.168.1.2 server2
In the output of my simple script I get the following result:
Parameter1: 192.168.1.1 - 1
- 2 eter2: server1
Parameter1: 192.168.1.2 - 1
- 2 eter2: server2
As you can see, the output of echo "Parameter2: $param2 - 2" is a completely strange line. For example, the number 2 at the end of the line appears in the beginning of the output.
I have spent some much time analyzing it, but I have not gotten anything.
Do you have any idea? Maybe the output from the servelet comes with 'broken' characters?
UPDATE:
I could solve this problem after reading the comments/answer below.
I just had to replace the /r /n from the servlet with the '/n' according to the unix style:
I've made it in one line:
param2="$(echo $param2 | dos2unix)"
You can find a lot of information here: Remove carriage return in Unix