Returning a value from a bash function

view full story

http://unix.stackexchange.com – I have a function which returns 1 if the number is a valid ten digit number: valNum() { flag=1 if [[ $1 != [1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] ]]; then echo "Invalid Number" flag=0 fi return $flag } It is getting called by: if [[ $(valNum $num) -eq 1 ]]; then #do something fi The function is working fine if the number is valid but is showing syntax error if input a invalid number. (HowTos)