Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git bash git bash if else在某些场景中失败_Git Bash - Fatal编程技术网

Git bash git bash if else在某些场景中失败

Git bash git bash if else在某些场景中失败,git-bash,Git Bash,我在WindowsGitBash上运行下面的代码 createDirectory() { if [[ -d $1 ]] then cd $1 else mkdir -p $1 fi } createDirectory "process1" createDirectory "process2" createDirectory "process3" createDirectory "process4&

我在WindowsGitBash上运行下面的代码

createDirectory() {

if [[ -d $1 ]]
then
  cd   $1
else
  mkdir -p  $1 
  fi
}

createDirectory "process1" 
createDirectory "process2" 
createDirectory "process3" 
createDirectory "process4"

它在第一次运行时创建4个文件夹。如果我删除一个文件夹,比如说rm-rf process3,然后尝试重新运行脚本,则无法检查并创建已删除的文件夹。为什么?我尝试了elif,而其他人仍然有相同的问题。

如果目录存在,你调用了cd,因此当你重新运行时,文件夹是在“process1”中创建的。嘿,谢谢,我收到了,这是一个错误,我没有意识到