Skip to content

Instantly share code, notes, and snippets.

@jrelo
Created August 22, 2019 13:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrelo/41efdbbdc72b244da9c3a3ba54d32a20 to your computer and use it in GitHub Desktop.
Save jrelo/41efdbbdc72b244da9c3a3ba54d32a20 to your computer and use it in GitHub Desktop.
if directory is empty
#!/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