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!

9
  • Instead of creating the directory tree is creates two directorys '{dir1,dir2/' and then '{subdir1,subdir2},dir3,dir4}' inside of the first. Commented Sep 5, 2015 at 0:56
  • This executes as expected for me, are you certain you are using the same command in both cases? Does the script contain any other commands that might alter this one? Commented Sep 5, 2015 at 1:09
  • Same for me. Are you sure you're not running it in sh/dash? Commented Sep 5, 2015 at 1:11
  • Yes I copy and paste the command out of my bash script. The command works manually but not in the script. And yes I am running bash for sure. Commented Sep 5, 2015 at 1:14
  • @techno-shaman Run bash -x yourscript, post output please Commented Sep 5, 2015 at 1:15

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.