echo "**********************" echo "Adding a new inhabitant..." echo "**********************" echo -n "Give me the first name of the inhabitant: " read fname echo -n "Give me the last name: " read lname echo -n "Give me the room number: " read room exists="true" while [ $exists == "true" ]; do echo -n "Please give me the code of the apartment you want to be added: " read code gawk '{print $NF}' apartment | if ( grep -q $code ); then echo "The code exists" else echo "Code successfully added" exists="false" echo "Now \"exists\" is $exists " fi done echo "Inhabitant: $fname $lname with room number $room live on $code" >> inhabitant_file echo Here is the apartment 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 Here is some strange output: Give me the first name of the inhabitant: test1 Give me the last name: check Give me the room number: A50 Please give me the code of the apartment you want to be added: 90 The code exists Please give me the code of the apartment you want to be added: 80 The code exists Please give me the code of the apartment you want to be added: 100 The code exists Please give me the code of the apartment you want to be added: 10 The code exists Please give me the code of the apartment you want to be added: 20 The code exists Please give me the code of the apartment you want to be added: 50 The code exists Please give me the code of the apartment you want to be added: 1 The code exists Please give me the code of the apartment you want to be added: 2 The code exists Please give me the code of the apartment you want to be added: 3 Code successfully added Now "exists" is false Please give me the code of the apartment you want to be added: ********** QUSETION 1: Code 1 exists?something wrong from grep? I see that it doesn't.. QUESTION 2:What can be done for the loop to break so the script writes the variables into the file? ***********