3

I'm cating a file, and the output is something like this:

Help me my friend
Temptation
Sorrow
True Love
Vanilla Sky
I was here
SOS
...

I'm trying to create directory of all of these lines.

What I have tried is:

mkdir `cat x.txt`

But the result is a mess! For instance, I was here will be split into three directories like I, was, and here. How can I fix this??

Thanks in advance.

Parsa Samet
  • 777
  • 1
  • 7
  • 20

1 Answers1

6

Read the lines one by one and use proper quoting:

while IFS= read -r name; do mkdir -- "$name"; done <x.txt
heemayl
  • 56,300
  • Wow, great quick answer thanks a million. Shall I ask you to explain what it does? And shall I ask you to tell me what if I wanted to do the same thing with the out-put of a command?? – Parsa Samet Aug 29 '16 at 13:14
  • 3
    @ParsaX Do: <your_command> | while ...; do ...; done – heemayl Aug 29 '16 at 13:20