I'm trying to create a directory with list of directories with list of files. Could you explain me, why this script doesn't work properly?
createapp() {
local folders=('graphql' 'migrations' 'models' 'tests')
local files=('__init__.py' 'admin.py' 'apps.py' 'views.py')
cd backend/apps
mkdir $COMMAND2
cd $COMMAND2
for folder in $folders
do mkdir $folder && cd $folder
for file in $files
do touch $file && cd ..
done
done
}
It creates a graphql directory, and an __init__.py file in it, but that's all.
for folder in $foldersdoes not iterate over the array.for directory in "${folders[@]}"cdcommand. Aftermkdir "$folder", just dotouch "$folder/$file". Right now, you are executingcd ..too soon: you want to do that after the file loop completes.