Home > Blockchain >  while executing this programe i getting same output every time as file not found even if file is ava
while executing this programe i getting same output every time as file not found even if file is ava

Time:11-30

give me this error:

" file not found "

Here are the full code

https://github.com/vats147/public/blob/main/l25.sh

#! /bin/bash

usage(){
     echo " you need to provide an argument "
     echo " usage : $0 file_ name "
}

is_file_exist(){
    local file="$1"
    [[ -f " $file " ]] && return 0 || return 1
} 
[[ $# -eq 0 ]] && usage
if(is_file_exist "$1")
then
    echo " file found "
else
    echo " file not found "
fi

while the executing of a programe i get same output as file not found even if file are avaliable in directory.

why?

CodePudding user response:

I think your if condition is invalid. It should be more like this

if [[ is_file_exist "$1" -eq 1 ]];then
    echo "file found"
else
    echo "file not found"
fi
  • Related