I want to write a simple check when running mkdir to create a directory. First, it checks if an existing directory exists, if it does, it will simply skip. If dir does not exist, it starts mkdir, if mkdir fails (this means that the script cannot create the directory because it does not have sufficient privileges), it will complete.
Here is what I wrote:
if [ ! -d "$FINALPATH" ]; then if [[ `mkdir -p "$FINALPATH"` -ne 0 ]]; then echo "\nCannot create folder at $FOLDERPATH. Dying ..." exit 1 fi fi
However, 2nd, if it seems, is not working correctly (I catch 0 as the return value for a successful mkdir). So, how to write the 2nd, if? and what makes mkdir successful as well as failure?
source share