Validating Input and Preconditions
Validating Input and Preconditions
Always validate preconditions before executing destructive actions:
# Validate argument count
[[ $# -ge 2 ]] || { echo "Usage: $0 <src> <dest>" >&2; exit 1; }
# Validate file existence and permissions
[[ -f "$1" ]] || { echo "Error: File $1 does not exist" >&2; exit 2; }
[[ -r "$1" ]] || { echo "Error: File $1 is not readable" >&2; exit 3; }