how to break cat

Greetings.

cat $name[tab]$telephonenumber >> telephonebook.txt

I would like to break cat with the command 'break'. Pretty hard to understand huh? So to clarify it:

echo "If you want to stop adding datas to your telephonebook please type 'break'
if [ $name = break ] #this part is probably not good
then
      echo "the program is shutting down..."
      #missing commands
else
      cat $name[tab]$telephonenumber >> telephonebook.txt
fi

Well no wonder...i get a syntax error. I think the first problem is with the $name = break part... i just don't know how to fix it.
And my second question would be: how can i pause the screen for a few seconds, so the user can read the text ("the program is shutting down..."), and how can i break the running program.
Thanks in advance, cheers:
buddhist

Presuming you are using this code within a loop...

  1. The missing command is break :slight_smile: :
break

This will exit the loop and then execute the rest of the code after the loop.

Alternatively you can use:

exit [errno]

to exit the script altogether

  1. To pause 5 seconds use:
sleep 5

IMHO you have misunderstood the assignment. Time to talk to your tutor. As scrutinizer hints, "break" is a unix shell command. It has other meanings too.

An example use of "break" in a shell script would be:

while true
do
    echo "To finish press return"
    echo "Enter name" ; read name
    if [ "${name}""X" = "X" ]
    then
          echo "the program is shutting down..."
          break          # Exit the while loop
    fi
    echo "Enter telephone number" ; read telephonenumber
    echo "${name} ${telephonenumber}" >> telephonebook.txt
done

BTW. It is much more complicated to react to a user pressing the key marked "break" on an IBM 102 key keyboard.