0

I have a text file /tmp/tmpGetFilefile-only. In the Text File it has the following (there is no blank line between the values)

goce

gocetengoce

When I run the below script

#!/bin/bash
while read -r line
  do
  echo "File: ${line}"
done < /tmp/tmpGetFilefile-only

I get this. As you can see the echo command is not working. Why is this so ?

./whileshh.sh

goce:
gocetengoce
goced
  • 61
  • 2
  • 9
  • 1
    Your file has crlf newlines, fix it with `dos2unix`. – Barmar Aug 01 '23 at 01:55
  • You can also get `read` to remove the carriage return with `while IFS=$'\r' read -r line` – Gordon Davisson Aug 01 '23 at 02:58
  • Your input lines have a carriage return somewhere (probably at the start of each line). You can verify this by looking at the file with a hex editor, or by doing a `xxd /tmp/tmpGetFilefile-only`. If you get weird output, always check your input for weird characters in it! And when you are asking such a question here on Stackoverflow, include the hexdump of your file. The file is small enough that showing a hexdump is reasonable. – user1934428 Aug 01 '23 at 06:25
  • @Barmar : THIS output would IMHO be better explained by a CR at the start of `$line`. – user1934428 Aug 01 '23 at 06:29

0 Answers0