Search code examples
bashindentationcurly-bracesbrace-expansion

How to write fancy-indented multi-line brace expansion in Bash?


I'm dealing with a line such :

mkdir -p "$DEST_ROOT_PATH/"{"$DEST_DIR1","$DEST_DIR2", ..., "$DEST_DIRN"}

This line is quite long. I want to cut it so its width will fit into a 80 columns line. I tried to escape an end of line with a backslash, but space alignement breaks the expansion :

$ echo "ha"{a,b,\
>           c}
ha{a,b, c}

Solution

  • You could use this disgusting hack.

    echo "ha"{a,b,\
    > `      `c}
    

    It opens a subshell with nothing in it, but gets processed before the expansion so the expansion just sees an empty space