Reputation: 127
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
Upvotes: 0
Views: 1411
Reputation: 189377
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[@]}"
Upvotes: 3
Reputation: 1373
path=`echo /parentfolder/{child_1,child_2}`
expansion needs a command to work properly.
Upvotes: 0