pankaj_ar
pankaj_ar

Reputation: 765

printf not printing line correctly bash unix

I am using printf command to log some values in a file as follows:

printf "Parameter = $parameter v9_value = $v9_val v9_line = $V9_Line_Count v16_val = $v16_val v16_line = $V16_Line_Count"

But the output I am getting as follows:

 v16_line = 8elayServerPort v9_value = 41 v9_line = 8 v16_val = 4571

Seems like the line is printed in rotation manner, and last values are coming from starting.

Expected Output:

Parameter = RelayServerPort v9_value = 41 v9_line = 8 v16_val = 4571 v16_line = 8

But v16_line = 8 is overwritten on Parameter = R in line.

Upvotes: 1

Views: 2245

Answers (1)

David W.
David W.

Reputation: 107040

printf doesn't add a NL on the end. You need to add \n to the end of your printf.

Not seeing the rest of your program, or where you get your variable values, it's hard to say what else could be the issue.

One thing you can do is to redirect your output to a file and look at that file either through a good program editor or using cat -v which disables control characters.

See if you see ^M in your output. If you do, it could be that you have ^R in your variables.

Also remove $v16_val from your printf (temporarily) and see if your output looks better. If so, that $v16_val might have a CR (^M) in it.

Upvotes: 1

Related Questions