0

txt with the following contents:

.workingDocuments
images
.database

I run a bash script (codespaces git bash shell):

while read -r line; do 
  mkdir "$line"
done < folders.txt

The script creates the folders but adds a special character  at the end of each folder?

.database
.workingDocuments
images

this will be part of a student activity so I specifically want to use a while loop with mkdir but I don't want the special character.

I have same issue with a similar script and file to create files using touch

Ben Jones
  • 504
  • 4
  • 18
  • 1
    Could be Windows line endings. Check out [How to convert DOS/Windows newline (CRLF) to Unix newline (LF)](/q/2613800/4518341) – wjandrea Aug 08 '23 at 00:35
  • @wjandrea I added echo $line and there is no special character it is occuring in the mkdir? I would assuem if it was a line ending issue it would also show in the echo? – Ben Jones Aug 08 '23 at 00:48
  • 1
    Your `folders.txt` file probably has Windows line endings (CR-LF). `echo $line` won't show them (and doesn't work in general). Use `declare -p line` instead. – pjh Aug 08 '23 at 01:47
  • 1
    This character must therefore be already present in folders.txt. Have a look at this file on a hexadecimal level, i.e. `xxd folders.txt`. – user1934428 Aug 08 '23 at 06:12
  • Running `cat -v folders.txt` should reveal the CR characters as `^M` at the end of each line. – pjh Aug 08 '23 at 10:47

0 Answers0