0

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

2
  • 1
    The Java servlet is returning lines ending with carriage-return/linefeed pairs. Commented Sep 5, 2016 at 20:37
  • Thanks chepner. You were right. Commented Sep 5, 2016 at 21:12

1 Answer 1

2

Maybe the output from the servelet comes with 'broken' characters?

Not broken per se, but it's returning CRLFs instead of just LFs which is causing the strange output. Strip the CRs before using the data.

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry Ignacio, but what do you mean by 'Strip the CRs'?
I could research more about it and I understand. I had to replace the '/r /n' by just '\n', according to the unix style, and it worked. Thanks a lot. I will update the question with the solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.