到目前为止,我有这个,我在所选文件夹中创建了我想要的文件夹数量。创建的文件夹数量取决于我的选择。
如何在每个文件夹中制作文件?我希望它们根据我选择的文件数量从 1 开始编号。
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
最佳答案
#!/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
阅读 Bash Manual .
关于linux - 如何根据用户选择按编号顺序创建多个文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70642630/