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 -
#!/bin/bash
-
# A menu driven Shell script which has following options
-
# Contents of /etc/passwd
-
# List of users currently logged
-
# Simple Calculator
-
# Exit
-
# As per option do the job
-
while :
-
do
-
clear
-
echo " M A I N - M E N U"
-
echo "1. Contents of /etc/passwd"
-
echo "2. List of users currently logged"
-
echo "3. Simple Calculator"
-
echo "4. Exit"
-
echo -n "Please enter option [1 - 4]"
-
read opt
-
case $opt in
-
1) echo "************ Conents of /etc/passwd *************";
-
more /etc/passwd;;
-
2) echo "*********** List of users currently logged";
-
who | more;;
-
3) a=$1
-
op="$2"
-
b=$3
-
-
if [ $# -lt 3 ]
-
then
-
echo "$0 num1 opr num2"
-
echo "opr can be +, -, / , x"
-
exit 1
-
fi
-
-
case "$op" in
-
+) echo $(( $a + $b ));;
-
-) echo $(( $a - $b ));;
-
/) echo $(( $a / $b ));;
-
x) echo $(( $a * $b ));;
-
*) echo "Error ";;
-
esac
-
echo "Press [enter] key to continue. . .";
-
read enterKey;;
-
4) echo "Bye $USER";
-
exit 1;;
-
*) echo "$opt is an invaild option. Please select option between 1-4 only";
-
echo "Press [enter] key to continue. . .";
-
read enterKey;;
-
esac
-
done
-
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
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
and i don get an error ?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Jim Irvine |
last post by:
Does anybody know the limit of nested iif statements you can use in Access?
|
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
|
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
|
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....
|
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
| |
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...
|
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...
|
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
|
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
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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...
|
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
| |
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...
| |