How to Check if a File or Directory Exists using Bash?
Using IF statement
FILENAME=/etc/conf.yml
if [ -f "$FILENAME" ]; then
echo "$FILENAME exists."
else
echo "$FILENAME does not exist."fi
Without using IF statement
[[ -f /etc/conf.yml ]] && echo "$FILENAME exists."
See below link for more details
https://linuxize.com/post/bash-check-if-file-exists/#check-if-directory-exist
No comments:
Post a Comment