473,800 Members | 2,731 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

nested case statements in linux

lifeisgreat20009
70 New Member
the simple script below is not working after i implemented a case statement within another..plz tell me where the problem lies...

My script is as follows

Expand|Select|Wrap|Line Numbers
  1. #!/bin/bash
  2. # A menu driven Shell script which has following options
  3. # Contents of /etc/passwd
  4. # List of users currently logged
  5. # Simple Calculator
  6. # Exit
  7. # As per option do the job
  8. while :
  9. do
  10.  clear
  11.  echo "   M A I N - M E N U"
  12.  echo "1. Contents of /etc/passwd"
  13.  echo "2. List of users currently logged"
  14.  echo "3. Simple Calculator"
  15.  echo "4. Exit"
  16.  echo -n "Please enter option [1 - 4]"
  17.  read opt
  18.  case $opt in
  19.   1) echo "************ Conents of /etc/passwd *************";
  20.      more /etc/passwd;;
  21.   2) echo "*********** List of users currently logged";
  22.      who | more;;
  23.   3) a=$1
  24. op="$2"
  25. b=$3
  26.  
  27. if [ $# -lt 3 ]
  28. then
  29.     echo "$0 num1  opr num2"
  30.     echo "opr can be +, -, / , x"
  31.     exit 1
  32. fi
  33.  
  34. case "$op" in
  35.     +) echo $(( $a + $b ));;
  36.     -) echo $(( $a - $b ));;
  37.     /) echo $(( $a / $b ));;
  38.     x) echo $(( $a * $b ));;
  39.     *) echo "Error ";;
  40. esac
  41.      echo "Press [enter] key to continue. . .";
  42.      read enterKey;;
  43.   4) echo "Bye $USER";
  44.      exit 1;;
  45.   *) echo "$opt is an invaild option. Please select option between 1-4 only";
  46.      echo "Press [enter] key to continue. . .";
  47.      read enterKey;;
  48. esac
  49. done
  50.  
Jan 2 '09 #1
2 7810
numberwhun
3,509 Recognized Expert Moderator Specialist
@lifeisgreat2000 9
I think you are a bit confused in all that you are trying to do with this script. First, I have never seen anyone try to nest case statements. Even if they did try though, wouldn't it make sense to nest it inside of one of the options from the previous menu?

Also, for #3, your simple calculator, it errors out because it expects input, but from where? Also, #2 doesn't even print anything and if it does, its so very fast it cannot be seen. Making the program wait till a key is pressed might be a good idea.

Regards,

Jeff
Jan 3 '09 #2
kaarthikeyapreyan
107 New Member
Hey where is the error, the script runs fine for me
I removed the clear to visualize the output of #1 and #2
and for #3 I ran the program the way it wanted it to be run
Expand|Select|Wrap|Line Numbers
  1. ./case.sh 1 + 5
and i don get an error ?
Feb 5 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4319
by: Jim Irvine | last post by:
Does anybody know the limit of nested iif statements you can use in Access?
5
13601
by: cbielins | last post by:
I have a problem, and would like you input... I need to evaluate to columns and then base a third column on their values. But, I need to include NULL values and this statement isn't working, what am I doing wrong? Is this possible? Example: CASE A1 WHEN NULL THEN CASE A2
0
3217
by: java7man | last post by:
All - below is part of a construct I am using. I have some very complex data and processing to perfrom and I need a way to get beyond case limitations. Anyone know of other more robust constructs available in SQL - DB2. The book says only 3 levels of nested case statements are allowed - that is true. Any assistance would be appreciated. select field1 , field2 ,case
1
2455
by: redpayne | last post by:
Ok-I am doing homework out of a book and the instructions are to display an interface with 5 option buttons in a frame. When clicked, each button changes the background color of the frame. It proceeds to tell me to construct CheckboxGroup, use FlowLayaout and add the Checkboxes to the frame along with ItemListener. It says addWindowListener()method, write code for itemStateChanged() which uses the getState() method and nested if statements....
6
1807
by: Fir5tSight | last post by:
Hi All, I have a "SELECT" statement in a stored procedure that looks like the follows: -------------------------------------------------------------------------------------------------------------- SELECT CASE WHEN ( ri.Status NOT LIKE '%COMPLETE%' ) -- report not completed
9
9331
by: paulyche | last post by:
I'm writing a program which contains an awful lot of nested if statements. I don't know how efficient this is but it definetely makes the code less readable. Does anyone have any advice on how I can improve the following kind of code? Apparently other languages have a switch statement which is useful here...Python seems to lack this functionality. My Python is self-taught so I'd appreciate any outside input. Lots of the code involves...
5
1593
patjones
by: patjones | last post by:
Hi: I have a table in my Access database, "tblWC", which contains a field called "fldTrackingStatus". Furthermore, I have a report "rptTrackingReport" which is based on tblWC (using an SQL query written out in VB). The report sorts all the records out by fldTrackingStatus, which can have an integer value between 1 and 5 inclusive. The problem is, the report is putting "1", "2", "3", etc. at the top of each tracking status sub-section. I...
1
1391
by: RAJ | last post by:
hi there, can anybody suggest me best sites for learning php with nested sql statements. i need sql query for searching from database with lots of options like using AND, OR etc even using multiple tables thanks, raj
0
1295
by: Neil Cerutti | last post by:
The docs say: A suite can be one or more semicolon-separated simple statements on the same line as the header, following the header's colon, or it can be one or more indented statements on subsequent lines. Only the latter form of suite can contain nested compound statements; the following is illegal, mostly because it wouldn't be clear to which if clause a following else clause would belong: if test1: if test2: print x
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10274
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10251
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10033
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.