0

I have the following script:

#!/bin/bash
path="/parentfolder/{child_1,child_2}"
mkdir -p $path
mkdir -p /parentfolder/{child_3,child_4}

Running it creates the following folders:

/parentfolder/{child_1,child_2}
/parentfolder/child_3
/parentfolder/child_4

How can I make the script create the following folder structure:

/parentfolder/child_1
/parentfolder/child_2
/parentfolder/child_3
/parentfolder/child_4
1
  • 1
    The manual explains how shell expansions work. Brace expansion occurs before parameter (variable) expansion, so the braces in the parameter value are not expanded. Commented Aug 22, 2015 at 7:58

2 Answers 2

3

You cannot use brace expansion in a quoted variable; either put the braces in the command itself, or assign the variable differently. If you need the values to be in a variable, using an array would seem suitable.

#!/bin/bash

paths=(/parentfolder/{child_1,child_2,child_3,child_4})
mkdir -p "${paths[@]}"
Sign up to request clarification or add additional context in comments.

Comments

0
path=`echo /parentfolder/{child_1,child_2}`

expansion needs a command to work properly.

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.