bash - Passing argument function not working -


valid() {  if [[ "$1" = "0" ]];         echo "pass file name argument"         exit 1  fi }  valid if [ -f $1 ];         echo "$1 exists" else         echo "$1 doesnt exist" fi 

in above example, vaild() function not working, why so? when valid argument passed checks file name , prints when not passed, prints "exists".

you should check null strings when taking string argument , not compare 0. need pass argument valid function.

valid() {  if [ -z "$1" ];         echo "pass file name argument"         exit 1  fi }  valid $1  if [ -f "$1" ];         echo "$1 exists" else         echo "$1 doesnt exist" fi 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -