linux - what happen in this script? -


#!/bin/sh  yes_or_no(){      echo "is name $* ?"     while true              echo -n "yes or no"         read x         case "$x" in              y | yes ) return 1;;              n | no ) return 0;;             * ) echo "answer yes or no"         esac      done     }  if  yes_or_no "$1"        echo "hi $1,nice name i" else      echo "never mind" fi  exit 0 

output-->

./fuction1.sh salman khan  name salman ?  yes or non  hi salman,nice name 

why opposite output cam if press no output never mind because fuction return 0. totally confuse here can any-buddy me solve this?

in shell things not in other languages. "0" code of success:

$ true $ echo $? 0 $ if true ; echo "true"; fi true 

from above can see 0 means "0 errors", while other "0" indicate error code. shell logic geared towards rather c-like 0 == false , 1 == true


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -