Search code examples
terminalechopipelinemkdir

Trying to pass the output of echo into mkdir command


I know that echo command prints all it's arguments and it does not reads from stdin.

But when I am trying to make echo NAME | mkdir it tells me: mkdir: missing operand.

I tried to read from man mkdir, but it does not tells me where mkdir reads from.


Solution

  • You're passing the name as input, mkdir expects an argument

    Try:

    echo NAME | xargs mkdir
    

    xargs here provides exactly the missing link: it takes the input stream, and passes it to the program (mkdir, in this case) as arguments. Note that this parses whitespace-separated elements as different args, so use this with care.

    For more information just look at man xargs