Created
August 22, 2019 13:04
-
-
Save jrelo/41efdbbdc72b244da9c3a3ba54d32a20 to your computer and use it in GitHub Desktop.
if directory is empty
This file contains 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 the variable for bash behavior | |
shopt -s nullglob | |
shopt -s dotglob | |
# Die if dir name provided on command line | |
[[ $# -eq 0 ]] && { echo "Usage: $0 dir-name"; exit 1; } | |
# Check for empty files using arrays | |
chk_files=(${1}/*) | |
(( ${#chk_files[*]} )) && echo "Files found in $1 directory." || echo "Directory $1 is empty." | |
# Unset the variable for bash behavior | |
shopt -u nullglob | |
shopt -u dotglob |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment