Function with return statement & Ternary Operator

#! /bin/bash
usage() {
    echo "You need to provide an argument"
    echo Syntax : $0 fileName
    exit 1
}
fileExist() {

    #echo The file we are search for $1
    [[ -f $1 ]] && return 0 || return 1
}
[[ $# -eq 0 ]] && usage

if ( fileExist "$1" )
then
    echo File found
else
    echo File not found
fi

Leave a Comment