0

I am attempting to create a recursive directory tree with some nested directories along the way.

While testing this manually in bash it functions without issue. However while testing this command in a bash script it is broken...instead of creating the directory tree, it creates two directories '{dir1,dir2/' and then {subdir1,subdir2},dir3,dir4} inside of the first.

Here is the command:

mkdir -p main/{dir1,dir2/{subdir1,subdir2},dir3,dir4}

Any thoughts?

Thanks!

chepner
  • 497,756
  • 71
  • 530
  • 681

1 Answers1

3

Your script is being run by /bin/sh, which in your case is not bash but rather some Posix-compatible shell, quite possibly dash.

Brace expansion is a shell extension implemented by quite a few shells, including bash, ksh and zsh, but it is not available in dash.

Make sure that your shebang line specifies bash:

#!/bin/bash
rici
  • 234,347
  • 28
  • 237
  • 341