gpt4 book ai didi

linux - 用于创建树目录的 Bash 脚本

转载 作者:太空宇宙 更新时间:2023-11-04 05:57:32 25 4
gpt4 key购买 nike

我这里有一个脚本,该脚本将列出当前工作目录中的所有目录并创建子目录以制作目录树,但问题是它无法创建目录。

有人可以帮我解决这个问题吗?该脚本必须在特定目录和子目录中创建一个目录

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com