So far I have this, where I create the number of folders I want within a chosen folder. The number of folders created is based on my choice.
How do I make files within every one of those folders? I want them to be numbered starting from 1, based on how many files I choose.
read -p "Enter the number of folders to create: " FOLDER_X
read -p "Enter the number of files to create: " FILE_Y
for (( x = 1; x <= FOLDER_X; x )); do
mkdir $DIRY/$x
done
for i in {"$FILE_Y"}
do
echo hello > "$i.txt"
done
CodePudding user response:
#!/bin/bash
shopt -s extglob
DIR=/path/to/somewhere
while :; do
read -p "Enter the number of folders to create: " folders
read -p "Enter the number of files to create: " files
[[ $folders,$files == ([[:digit:]]), ([[:digit:]]) ]] && break
echo "Please provide numeric inputs."
done
for (( i = 0; i < folders; i )); do
mkdir -p "$DIR/$i" || break
for (( j = 0; j < files; j )); do
echo hello > "$DIR/$i/$j.txt" || break 2
done
done
Read the Bash Manual.
