Search code examples
bashmkdir

Bash line continuation with parameter expansion


This

mkdir -p a/{b,c}

makes the directory structure:

a
|-- b
`-- c

However, this

mkdir \p a/{ \
   b, \
   c \
   }

causes this to happen:

|-- }
|-- a
|   `-- {
|-- b
|-- ,c

Why is that? Is there a fix?


Solution

  • You can not have unquoted spaces in brace expansions. This will cause the brace expansion to fail and instead be passed as a literal strings (which is why you instead create directories named }).

    It works if you delete all the spaces:

    mkdir -p a/{\
    b,\
    c\
    }