Bash loop control while if else with a return
问题 I need to return a true or false if I find a value within a file. I parse the file and if the value is located once which is enough, I want to break and return a true else return false. On top of it I need to pass the file into this check function. I'm trying to only use bash. is_file_contains_VAR(){ VARFILENAME=$1 while read LINE do if echo "$LINE" | grep -q "$VAR"; then break return 0 else return 1 fi done < $VARFILENAME } 回答1: grep -q already does what you want: it will abort as soon as it