Check If File Is Empty OR Not by Bash Script
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 | |
_file="$1" | |
[ $# -eq 0 ] && { echo "Usage: $0 filename"; exit 1; } | |
[ ! -f "$_file" ] && { echo "Error: $0 file not found."; exit 2; } | |
if [ -s "$_file" ] | |
then | |
echo "$_file has some data." | |
# do something as file has data | |
else | |
echo "$_file is empty." | |
# do something as file is empty | |
fi |
Comments
Post a Comment