473,383 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

nested case statements in linux

lifeisgreat20009
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 7785
numberwhun
3,509 Expert Mod 2GB
@lifeisgreat20009
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
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
by: Jim Irvine | last post by:
Does anybody know the limit of nested iif statements you can use in Access?
5
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,...
0
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...
1
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...
6
by: Fir5tSight | last post by:
Hi All, I have a "SELECT" statement in a stored procedure that looks like the follows: ...
9
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...
5
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...
1
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.