0

Strange "?" got added to the filename output.

SCRIPTS="/path_to_script/"
SUMMER=`cat /path_to_file/summer.txt`

for i in ${SUMMER};
  do cat <<- EOF > $SCRIPTS/20190430_$(echo ${i})_step4.r
#content omit
EOF
   done

Expected ourput would be

20190430_spring1_step4.r
20190430_spring2_step4.r
20190430_summer1_step4.r
20190430_summer2_step4.r

But I got the question mark after each variable except the last row from the ${SUMMER}.

20190430_spring1?_step4.r
20190430_spring2?_step4.r
20190430_summer1?_step4.r
20190430_summer2_step4.r

What is the problem? ${SUMMER}is a txt file with only one column

Molly_K
  • 161

1 Answers1

2

The file contains CR+LF (DOS/Windows style) line endings. These question marks are just ls denoting CR characters that survived. CR characters are literally in the names of the files. The last name is OK probably because the last line in the file has no line ending at all.

To confirm this invoke file /path_to_file/summer.txt. I guess the tool will tell you about "CRLF line terminators".

Use dos2unix to convert the file to Unix format first.

  • That makes a lot of sense. I will install dos2unix first and see if that works. Thank you. – Molly_K Apr 30 '19 at 17:09
  • Thanks, it works perfectly. No more odd question marks in the filenames. – Molly_K Apr 30 '19 at 17:16
  • Note that the question marks were never part of the filenames. It is how ls shows non-printable characters. The non-printable character was a carriage return character. – Kusalananda Apr 30 '19 at 17:22