This question already has an answer here:

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

Help me my friend
True Love
Vanilla Sky
I was here

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.

marked as duplicate by don_crissti, Stéphane Chazelas shell-script Aug 29 '16 at 13:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Read the lines one by one and use proper quoting:

while IFS= read -r name; do mkdir -- "$name"; done <x.txt
  • 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

Not the answer you're looking for? Browse other questions tagged or ask your own question.