break: cannot break


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting break: cannot break
# 1  
Old 05-06-2010
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 to the previous menu that person has to press Control + C and Enter Key

all my server are centos 5.0

I am adding my menu here

basically you execute ./menu

After that go to option

9. Opciones
7. Ejecutar comando
and execute a command like pwd
after that
Press Control + C and Enter Key


but I got error ./menu: break: cannot break
but in other servers pressing Control + C and Enter Key goes back to previous menu

any idea how to fix that?
or another way to exit from that simulated command line and go back to previous menu where I selected 7. Ejecutar comando

Basically this is the part that has issues

Code:
##Shell simulada para ejecutar commandos 
ejecutacmd ()
{
header
echo -e "${bold}Press Control+C and Enter Key to go back to previous menu${offbold}"
echo -e " "
while true ; do
     read whichcmd?"Enter Command: "
     if [ $(sudo -l | grep -c "$whichcmd") -gt 0 ] ; then
          sudo $whichcmd
     else
          $whichcmd
     fi
done
}

menu (code) is attached so you can see all options
thanks a lot

Update
Uploaded as menu.txt just remove .txt and test it

Last edited by karlochacon; 05-06-2010 at 03:05 PM..
# 2  
Old 05-06-2010
Hammer & Screwdriver Please do not include your code as zip files

Zip files can potentially include viruses, etc... Further, they complicate the whole process of assisting in solving the problems.
If your example is too large, simply cut/paste a few records/rows of data into your post (making sure to enclose it inside codetags).
# 3  
Old 05-06-2010
Quote:
Originally Posted by joeyg
Zip files can potentially include viruses, etc... Further, they complicate the whole process of assisting in solving the problems.
If your example is too large, simply cut/paste a few records/rows of data into your post (making sure to enclose it inside codetags).
I will add it as txt

---------- Post updated at 07:26 PM ---------- Previous update was at 02:03 PM ----------

well guys I ended doing this

I don't know if it's the best way but that's the only thing that came to my mind

Code:
ejecutacmd ()
{
header
echo -e "Digite ${bold}end${offbold} para finalizar"
echo -e " "
while [ "$whichcmd" != end ]
do
     read whichcmd?"Enter Command: "
     $whichcmd
done
whichcmd=0

# 4  
Old 05-06-2010
I would just prompt the user to press enter when done. The read will set whichcmd to an empty string, and you can test that to break the loop.

Code:
read whichcmd
[ "$whichcmd" ] || break

Regards,
Alister
# 5  
Old 05-06-2010
Quote:
Originally Posted by alister
I would just prompt the user to press enter when done. The read will set whichcmd to an empty string, and you can test that to break the loop.

Code:
read whichcmd
[ "$whichcmd" ] || break

Regards,
Alister

not possible since like I said it is a basic command line so user can execute

pwd cd ifconfig ......

so he needs to press enter every time he runs a command
# 6  
Old 05-06-2010
Yes. I understand that. But if the user presses enter without typing a command, that can be use to signal the break in the while loop.
# 7  
Old 05-07-2010
Quote:
Originally Posted by alister
I would just prompt the user to press enter when done. The read will set whichcmd to an empty string, and you can test that to break the loop.

Code:
read whichcmd
[ "$whichcmd" ] || break

Regards,
Alister
now I get it but I need it in a loop... Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Break vs Continue

Okay so I am having trouble understand what the computer will do with a code like this if ; then echo echo "Found the file" blah blah blah for i in `blah blah blah` ; do ... (2 Replies)
Discussion started by: shade917
2 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

how to break cat

Greetings. cat $name$telephonenumber >> telephonebook.txtI 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 #this part is probably not good then echo... (2 Replies)
Discussion started by: buddhist
2 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

help on page break

Hi, i have a file say samp.s which has 123 a b c d 123 e f g h 123 i j k l 123 m n o p 234 a b c d 234 e f g h 234 i j k l the first 3 characters in each line are considered the key values i have one more file temp.txt which has 123 234 i want to have a page break in... (5 Replies)
Discussion started by: Sheema
5 Replies

6. 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

7. Shell Programming and Scripting

Break command

have a query on this break. I am using a program where I am using a while loop to execute it. It will get into a file take the first file and then ping it and if the ip is reachable then it will mail. Now what happens is that when i ping the ip it does nopt come out of the loop and it says "reply... (11 Replies)
Discussion started by: venkidhadha
11 Replies

8. Solaris

send break

Does anyone know how to send break on a Blade 100? I'm using a serial cable on my laptop and I can see the system boot up just fine, but I want to send break so i can have it boot from cdrom instead of disk. (3 Replies)
Discussion started by: em23
3 Replies

9. 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

10. Shell Programming and Scripting

TO break a line

hi All, Have a doubt in ksh..Am not familiar with arrays but i have tried out a script.. plzzzzz correct me with the script My i/p File is: (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (Host = 192.168.2.2) (Port = 1525) ) ) (CONNECT_DATA = (SID = TESTDB1) ) ) ... (7 Replies)
Discussion started by: aajan
7 Replies
Login or Register to Ask a Question