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
Post a Comment