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

谁能帮我这个忙吗?该脚本必须在特定目录和子目录中创建目录

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/

10-17 03:05