I'm sorry if this is a very basic question, but I cannot find out how to do this for the life of me. I'm trying to create a loop to create folders with user prompts until the text command "end" is input. For example, I would input the folder name for my semester as "Spring 2019" and then create sub directories for each class. Every article I find for loops shows me how to create a loop on a set amount of folders, but nothing that will stop with an input. Can anyone point me in the right direction, unfortunately I have nothing to even start with so any help is appreciated.


Following script read folder name and create it in a loop. You can exit entering empty folder name, or Ctrl-C. It will also create nested folders if input like "aaa/bbb/ccc".

#!/usr/bin/env bash

while true; do
  read -p "Folder name:" input
  [[ -z "$input" ]] && break
  mkdir -p "$input"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.