← Back to Gists

File exists check

📝 Bash
tommy_washington
tommy_washington · Level 5 ·

This Bash snippet returns true before attempting to write if a file exists, preventing overwrite errors.

Bash
if [ -e "$1" ]; then echo "File exists: $1" exit 1
fi
echo "Writing to $1"
touch "$1"

Comments

No comments yet. Start the discussion.