Many of the answers are correct, but I feel they can be more complete / simplified, etc., for example:
Example 1. The basic if statement
# BASH4+ example on Linux : typeset read_file="/tmp/some-file.txt" if [ ! -s "${read_file}" ] || [ ! -f "${read_file}" ] ;then echo "Error: file (${read_file}) not found.. " exit 7 fi
if $ read_file is empty or not, stop showing up. I read the top answer more than once to indicate the opposite.
Example 2: as a function
# -- Check if file is missing /or empty -- # Globals: None # Arguments: file name # Returns: Bool # -- is_file_empty_or_missing() { [[ ! -f "${1}" || ! -s "${1}" ]] && return 0 || return 1 }
Mike Q Apr 29 '18 at 18:27 2018-04-29 18:27
source share