xxxxxxxxxx
#!/bin/bash
file_path="/path/to/file.txt"
if [ -e "$file_path" ]; then
echo "File exists."
else
echo "File does not exist."
fi
xxxxxxxxxx
FILE=/etc/resolv.conf
if [ -f "$FILE" ]; then
echo "$FILE exists."
else
echo "$FILE does not exist."
fi
xxxxxxxxxx
if [ -f "myFile.txt" ]; then
echo "File found"
fi
if ! [ -f "myFile.txt" ]; then
echo "File not found"
fi
// or as a bash function
openAnything() {
if [ -f "$@" ]; then // if file exist, open file...
code $@ // add your prefered editor/program
else
open $@ // if file not exist open as directory in finder
fi
}
xxxxxxxxxx
FILE=/etc/resolv.conf
if [ -f "$FILE" ]; then
echo "$FILE exists."
fi