Skip to main content
2 of 3
added 18 characters in body
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k

When reading a line from the DOS-formatted text file into the three variables, the last one, state, will have a carriage-return character at the end. This is because DOS text files denote "newline" using the character sequence CR+LF (carriage-return followed by line-feed). Unix text files only use line-feed for newline, and the carriage-return of the DOS text file is treated as any other character at the end of the line.

When outputting $state, this carriage-return character causes the position of the output to jump to the start of the line (this is the purpose of the carriage-return, to return the "carriage" (of the line printer, once upon a time) to the start of the line) and the following string to be placed at the very start of the line, over-writing any text previously outputted at these positions in the terminal.

So you get, for the first line,

'companyName=&address1=123&city=Fake&state=

followed by the value of $state, St Miami FL, and then the cursor is warped back to the start of the line, where

&urbanCode=&zip='

is outputted, overwriting the first part of the line, resulting in the weird-looking

&urbanCode=&zip='ress1=123&city=Fake&state=St   Miami   FL
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k