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.
1 Answer
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"
done
while
loop, and test the input variable for the word 'end' This article https://www.cyberciti.biz/faq/bash-while-loop/ explains the process, and has an example using a file read.break
from awhile
loop based on the result of a case statement