How to use Bash to create a folder if it doesn't already exist?

前端 未结 6 1344
暖寄归人
暖寄归人 2020-12-02 06:43
#!/bin/bash
if [!-d /home/mlzboy/b2c2/shared/db]; then
    mkdir -p /home/mlzboy/b2c2/shared/db;
fi;

This doesn\'t seem to work. Can anyone help?<

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 07:19

    Cleaner way, exploit shortcut evaluation of shell logical operators. Right side of the operator is executed only if left side is true.

    [ ! -d /home/mlzboy/b2c2/shared/db ] && mkdir -p /home/mlzboy/b2c2/shared/db
    

提交回复
热议问题