我这里有一个脚本,该脚本将列出当前工作目录中的所有目录并创建子目录以制作目录树,但问题是它无法创建目录。
有人可以帮我解决这个问题吗?该脚本必须在特定目录和子目录中创建一个目录
LIST=`ls -D`
for i in $LIST;
do
mkdir -p $i"/Dir3/Dir4/"
done
最佳答案
Don't parse the output of ls
.
这是“正确”迭代目录的一种方法:
for dir in */; do
# ^-- the trailing slash makes $dir expand to directories only
[ -d "${dir}" ] || continue
mkdir -p "${dir}/Dir3/Dir4/"
done
关于linux - 用于创建树目录的 Bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23382857/