while true; do echo -n "Give me the code of that house: " read code ; namef=$(awk NR==1'{print $5}' apartments_file) if grep -q " $code $" apartments_file; then echo "There is already a house named $namef with that code." ; echo -n "Please try again: "; else echo "Apartment name: $name with code $code" >> apartments_file; echo "Apartment name: $name with code $code added successfully." break fi ; done ; break ; [simeon@localhost project]$ cat apartments_file Name of the apartment: "house1" with code :: 90 Name of the apartment: "house2!" with code :: 80 Name of the apartment: "rush hour" with code :: 100 Name of the apartment: "fly away" :: 10 Name of the apartment: "flying high" :: 20 Name of the apartment: "into the summer sky" with code :: 50 and some output of the script: ********************** Adding a new apartment... ********************** Give me the name of the apartment house: same_house_testing Give me the code of that house: 90 There is already a house named "house1" with that code. Please try again: Give me the code of that house: 90 There is already a house named "house1" with that code. Please try again: Give me the code of that house: 100 There is already a house named "house1" with that code. Please try again: Give me the code of that house: