how to break cat


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to break cat
# 1  
Old 11-29-2009
how to break cat

Greetings.
Code:
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:
Code:
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
# 2  
Old 11-29-2009
Presuming you are using this code within a loop...

1. The missing command is break Smilie :
Code:
break

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

Alternatively you can use:
Code:
exit [errno]

to exit the script altogether

2. To pause 5 seconds use:
Code:
sleep 5


Last edited by Scrutinizer; 11-29-2009 at 08:27 AM..
# 3  
Old 11-29-2009
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:

Code:
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Break in for loop

in my python script i have loop like below: for item in itemlist: if <condition>: <code> else: <code> if <condition>: if <condition>: <code> else: for type in types: if... (1 Reply)
Discussion started by: ctrld
1 Replies

2. Shell Programming and Scripting

BASH: Break line, read, break again, read again...

...when the lines use both a colon and commas to separate the parts you want read as information. The first version of this script used cut and other non-Bash-builtins, frequently, which made it nice and zippy with little more than average processor load in GNOME Terminal but, predictably, slow... (2 Replies)
Discussion started by: SilversleevesX
2 Replies

3. Shell Programming and Scripting

break: cannot break

hi guys I am working on a menu for linux... some basic stuff. but I have an issue. I got 1 server where something is working and the same thing does not work in the same way in another linux box Basically I am simulating a command line where user insert some commands and to end and go back... (7 Replies)
Discussion started by: karlochacon
7 Replies

4. Shell Programming and Scripting

Break down a string

I am wondering how can I take a variable that may have multiple items of data and to use each one indenpendently. For example lets say that.... data=/lcl/apps/trm, /lcl/apps/wwe, /prd/sse/qwe, /lcl/ppe/eer Now I would like to be able to process each item found within the data string. As... (5 Replies)
Discussion started by: LRoberts
5 Replies

5. Shell Programming and Scripting

How to break record

I have this script lines #!/usr/bin/bash my_path=`dirname $0` I_table=$1 echo $I_table in I_table entry going is ccc_con,cc_gui I want to break content of I_table in S_Table and T_table on basis of comma as separtor (2 Replies)
Discussion started by: scorp_rahul23
2 Replies

6. Shell Programming and Scripting

cat in the command line doesn't match cat in the script

Hello, So I sorted my file as I was supposed to: sort -n -r -k 2 -k 1 file1 | uniq > file2 and when I wrote > cat file2 in the command line, I got what I was expecting, but in the script itself ... sort -n -r -k 2 -k 1 averages | uniq > temp cat file2 It wrote a whole... (21 Replies)
Discussion started by: shira
21 Replies

7. Shell Programming and Scripting

break out of 'if'

is it possible? because i still need to keep on reading even though i don't want to read that particular line (7 Replies)
Discussion started by: finalight
7 Replies

8. Shell Programming and Scripting

for i in `cat myname.txt` && for y in `cat yourname.txt`

cat myname.txt John Doe I John Doe II John Doe III ----------------------------------------------------------------------- for i in `cat myname.txt` do echo This is my name: $i >> thi.is.my.name.txt done ----------------------------------------------------------------------- cat... (1 Reply)
Discussion started by: danimad
1 Replies

9. UNIX for Dummies Questions & Answers

Difference between cat , cat > , cat >> and touch !!!

Hi Can anybody tell the difference between Difference between cat , cat > , cat >> and touch command in UNIX? Thanks (6 Replies)
Discussion started by: skyineyes
6 Replies
Login or Register to Ask a Question