0

I'm trying to create folders given an array of strings. I know it's a newbie question but I'm just starting bash scripting.

#!/bin/bash

declare -a lessons=(
  "Lesson 1 - Arrays" 
  "Lesson 2 - Classes"
)

for i in ${lessons[@]}
do
  mkdir $i
done
alex
  • 335
  • 6
  • 17
  • 2
    Quote all expansions - `for i in "${lessons[@]}"; do mkdir "$i"; done` – Inian Aug 07 '19 at 06:50
  • Actually, any POSIX `mkdir` will accept a series of strings as argument. So, just replace the whole loop with the statement: `mkdir "${lessons[@]}"` – John1024 Aug 07 '19 at 06:54
  • both worked can you create the answer so I can up vote them? – alex Aug 07 '19 at 06:56

0 Answers0