Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

bash check file exists

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
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #bash #check #file #exists
ADD COMMENT
Topic
Name
5+3 =