Shouldn't a mkdir -p $pidfolder be enought, since it won't create it if exists, no need for if statement?