Last active
August 29, 2015 14:05
-
-
Save gotnix/bf2b20eaa284c1664a9b to your computer and use it in GitHub Desktop.
Bash 脚本常用自定义函数,希望以后能多多更新
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| #set -x | |
| ####################################### | |
| # 检查目录是否为空目录 | |
| # Globals: | |
| # None | |
| # Arguments: | |
| # dir: 待检查的目录 | |
| # Returns: | |
| # 0: 目录为空 | |
| # 1: 目录非空 | |
| ####################################### | |
| dir_is_empty () { | |
| local dir=${1} | |
| if [[ -z $(find "${dir}" -depth -maxdepth 0 -type d -empty) ]]; then | |
| return 1 #not empty | |
| else | |
| return 0 #is empty | |
| fi | |
| } | |
| if dir_is_empty /tmp/; then | |
| echo 'empty' | |
| else | |
| echo 'no empty' | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment