Sponsored Content
Homework and Emergencies Homework & Coursework Questions Problem with executing a possible if or case statement script Post 302522327 by agama on Saturday 14th of May 2011 11:32:21 AM
Old 05-14-2011
Toward getting your current script working:

1) The ecase statement is in the wrong place. Move it up.

2) You don't need to (shouldn't) put more phonelist in an echo statement. The results of this are certainly unpredictable at best. The output from the more command is captured by the shell and used as the parameter for the echo command. From this perspective, the user might be given a prompt (--more--) before they see any output, or they may never be prompted and the text written by the echo command would scroll by unchecked; either of these cases would be confusing. Further, if your phone book is large, the amount of text placed on the echo command might exceed system limits and cause an error. Simply coding the command and its parameters as a statement in the script is all you need here.

In general, I don't think that it is good form to ever execute a command that naturally expects user input using back ticks or when using the preferred $(command) syntax. These imply that the output from the command is to be saved or passed to another command/function and that human intervention might not be appropriate.

3) You are not reading choice from the user, yet you test for it.

I'd also recommend using double bracketed expressions ([[ expression ]]) as they are much more efficient. All of the modern Bourne derived shells support this syntax. When using this notation, you do need to use == to test for equality.

If you are using Kshell, then you can have the shell test for syntax errors which might help with your debugging. If your script is in the file pb.ksh then this command can be used to test for syntax issues:

Code:
ksh -n pb.ksh

When I ran your original script through Kshell this way the output was this:
Code:
$ ksh -n  pb.ksh
t16.ksh: syntax error at line 16: `[' unexpected

Which immediately pointed out that the esac was misplaced.


Im not a bash user per se, but I believe that bash has a similar option/feature to syntax check if you prefer to use bash.

Hope this helps get you going again.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Case statement problem

I need to display this menu and accept variables. Can someone tell me why i am having a problem with this case statement, please # TAPE MANAGER MAIN MENU tapemgr_Main_Menu() { echo "Legato Tape Management System Menu" echo " This system is used to report Legato ERV Offsite and Tapes... (6 Replies)
Discussion started by: gzs553
6 Replies

2. Shell Programming and Scripting

what is problem with this small shell script.. case statement related

Hi All, this small script is written to recognize user input character.. it is in small case .. upeer case or is a number... but when i input first capital letter say A.. it always gives small character.... what is the problem. #!/bin/bash echo "Enter the character" read a case $a in )... (2 Replies)
Discussion started by: johnray31
2 Replies

3. Shell Programming and Scripting

shell script case statement

In a case statement like below : case $rental in "car") echo "For $rental Rs.20 per k/m";; "van") echo "For $rental Rs.10 per k/m";; "jeep") echo "For $rental Rs.5 per k/m";; "bicycle") echo "For $rental 20 paisa per k/m";; *) echo "Sorry, I can not gat a $rental for you";;... (4 Replies)
Discussion started by: sriram003
4 Replies

4. Shell Programming and Scripting

Problem with case statement

Hi, I need modify the all lines in a file into one format. cat file htec.twe34c.ATI .hesh.twdghu..ATI ..hesh.twdghu..ATI htec.twe3 hjsct14567ati Output should have 16 characters htectwe34c ATI heshtwdghu ATI heshtwdghu ATI htectwe3 ATI hjsct14567 ATI (4 Replies)
Discussion started by: kartheek
4 Replies

5. Shell Programming and Scripting

Problem with CASE statement

Guys, Here is the script syntax which is not accepting the parameters & not performing the said activity. $ ./routing.sh xyz123-ra str enable ********************************************************************** Preparing to service the request for Device xyz123-ra in Question... (9 Replies)
Discussion started by: raghunsi
9 Replies

6. Shell Programming and Scripting

Problem using 'Case' statement

Hi, When I execute the below script, I am getting the error as ' is not expected.ror at line 3 : `in #!/bin/sh case $1 in -r) echo Force deletion without confirmation ;; -i) echo Confirm before deleting ;; *) echo Unknown argument ;; esac I could not see any problem with... (1 Reply)
Discussion started by: Sathish_Obla
1 Replies

7. Shell Programming and Scripting

Help With Loop in Case Statement script

I am writing a bash script that asks the user for input and I need it to repeat until the user selects quit.. I dont know how to write the loop for it I searched all over but i still do not get it.. if anyone could help with this it would be greatly apprciated here is my script so far: #!... (2 Replies)
Discussion started by: Emin_Em
2 Replies

8. Shell Programming and Scripting

Problem using bash case statement

I have the following bash script and it is not accepting the lines "--"|"--""-") "--""-"") while do echo "Current Argument is ${1}" case "$1" in "--"|"--""-") echo "Argument is ${1}" shift # Skip ahead one to the next argument. ... (1 Reply)
Discussion started by: kristinu
1 Replies

9. Shell Programming and Scripting

Case Statement for Login/Logoff Script

I'm currently trying to write a login script. I have already written a logoff script that uses an if/else statement. #!/bin/bash TIMED=$(date +%H) if ' then echo Have a Great Day $USER else echo Have a Great Night $USER fi But I'd like to write one that give me the option of... (1 Reply)
Discussion started by: bbowers
1 Replies

10. Shell Programming and Scripting

[Solved] Strange Problem in case statement while shift

Hi, Here is my code as below: test.ksh: ======= #!/bin/ksh option="${1}" while do case $1 in -f) FILE="${2}" echo "File name is $FILE" ;; -d) DIR="${2}" echo "Dir name is $DIR" ;; -*) echo "`basename ${0}`:usage: | " (5 Replies)
Discussion started by: zaq1xsw2
5 Replies
IMON(1) 						    Linux System Administration 						   IMON(1)

NAME
imon - watch ISDN activities SYNOPSIS
imon [ -q] [-p phonebook] DESCRIPTION
imon is a ncurses based utility for watching ISDN activity. OPTIONS
-q If this option is given, the facility of terminatig the program by pressing 'Q' is disabled and the signals SIGHUP and SIGINT are caught. This option is intended for starting imon from within an rc script with redirecting input/output to some otherwise unused virtual console at boot time. -p phonebook is used to supply imon with a phonebook file. The format of a phonebook file is very simple: Every line has two elements separated by a TAB. The first element is a phone number which can contain wildcards. The second element is a descriptive string. For each active connection, this string is shown instead the phone number. Pressing 'S' toggles between display of strings and phone numbers. Pressing 'R' rereads the phonebook file in case of changes during program execution. AUTHOR
Fritz Elfert <fritz@isdn4linux.de> SEE ALSO
ttyI(4), isdnctrl(8), isdninfo(4). isdn4k-utils-3.25 1999/09/06 IMON(1)
All times are GMT -4. The time now is 03:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy