我在这里创建一个目录,如果该目录已经存在,则应跳过该步骤,我尝试了一个但失败了。有人可以帮忙吗?

build_major=$(cat build.major)
build_minor=$(cat build.minor)
build_servicePack=$(cat build.servicePack)
build_patch=$(cat build.patch)
build_hotfix=$(cat build.hotfix)
build_number=$(cat build.number)
if[ -d "${build_major}.${build_minor}.${build_servicePack}.${build_patch}.${build_hotfix}_${build_number}" ];
then
    cp file.txt /${build_major}.${build_minor}.${build_servicePack}.${build_patch}.${build_hotfix}_${build_number}
else
    mkdir ${build_major}.${build_minor}.${build_servicePack}.${build_patch}.${build_hotfix}_${build_number}
    cp file.txt /${build_major}.${build_minor}.${build_servicepack}.${build_patch}.${build_hotfix}_${build_number}
fi


但是失败的命令未找到错误

最佳答案

现在假设相对路径:

if [ ! -d "./mydirname" ]
then
  mkdir ./mydirname
fi

关于linux - 如果使用Shell脚本已经存在目录,如何避免mkdir?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56595527/

10-15 01:29