Skip to content

Instantly share code, notes, and snippets.

@gotnix
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save gotnix/bf2b20eaa284c1664a9b to your computer and use it in GitHub Desktop.

Select an option

Save gotnix/bf2b20eaa284c1664a9b to your computer and use it in GitHub Desktop.
Bash 脚本常用自定义函数,希望以后能多多更新
#!/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