Bash Shell script to check the existence of a file under your linux filesystem

Here is a very small but useful shell script that will check the existence of a file and report accordingly.

#!/bin/bash
#by alok srivastava
#check the existence of a file under your filesystem
#this bash shell script use "positional parameters"

file=$1
[ $# -eq 0 ] && { echo "Usage: $0 filename"; exit 999; }
if [ -f $file ];
then
echo "YES - File $file exists."
else
echo "NO - File $file does NOT exists."
fi

It can be very useful while creating more complex bash shell scripts.

Here is a sample execution shown for your reference:

Advertisements