LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Closed Thread
  Search this Thread
Old 11-02-2012, 07:58 AM   #1
millscourtney47
LQ Newbie
 
Registered: Nov 2012
Posts: 7

Rep: Reputation: Disabled
I need to ask 5 questions and run a command for each question answer if chosen


Hi guys im trying to ask a list of 5 questions but with each question answer there can be a seperate command for example if question 1 is chosen run this command if 2 then run this command and so forth. whats the best way to do this thanks
i have done this so far but i am getting unexpcted end of file;

#!/bin/bash

# define server
M3 SERVER 192.168.244.11

# don't run in anything but /opt
if [[ "$PWD" != "/opt" ]]; then
echo "This script must be run in /opt or not at all"
exit
fi
# network delay 100mbs
echo "!!!Type the delay you wish to make for example 100!!!"
echo "do you wish to slow down your network by 100"
echo "do you wish to slow down your network by 300"
echo "do you wish to slow down your network by 600"
echo "do you wish to slow down your network by 1000"
echo "do you wish to slow down your network by 2000"
read NETWORK
if [ "$NETWORK" == "100" ]; then
`tc qdisc add dev eth0 root netem delay 100ms`
if [ "$NETWORK" == "300" ]; then
`tc qdisc add dev eth0 root netem delay 300ms`
if [ "$NETWORK" == "600" ]; then
`tc qdisc add dev eth0 root netem delay 600ms`
if [ "$NETWORK" == "1000" ];then
`tc qdisc add dev eth0 root netem delay 1000ms`
if [ "$NETWORK" == "2000" ];then
`tc qdisc add dev eth0 root netem delay 2000ms`
fi

# Run Network
echo "Do you wish to disable network delay y/n"
read DISABLE
if [ "$NETWORK" == "y" ];then
`tc qdisc add dev eth0 root netem delay 0ms`
fi
 
Old 11-02-2012, 08:08 AM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
You must have a fi for every ones of your if, that is why you get the error.
In the future, please use code-tags to post code, that will preserve the formatting and make your posts more readable.
 
Old 11-02-2012, 09:16 AM   #3
shahinism
LQ Newbie
 
Registered: Aug 2012
Distribution: Slackware
Posts: 15

Rep: Reputation: Disabled
Well first of all you have to close all if statements with an fi, and not just the last one. Instead of that you can use 'if elsif fi' and this would be nicer than that you used. but the most best way is case statement. Here I made a menuish like script:
Code:
#!/bin/bash
while :
do
   clear
   echo "What command do you choose?"
   echo "---------------------------"
   echo "1. command 1"
   echo "2. command 2"
   echo "3. command 3"
   echo "4. Exit"
   read -p "Enter your choice [1-4]: " choice
   case $choice in
     1)
       echo "command 1 executed"
       read -p "Press [Enter] to continue" readEnterKey
       ;;
     2)
       echo "command 2 executed"
       read -p "Press [Enter] to continue" readEnterKey
       ;;
     3)
       echo "command 3 executed"
       read -p "Press [Enter] to continue" readEnterKey
       ;;
     4)
       exit 0
       ;;
     *)
       echo "Wrong input, try something else..."
       read -p "Press [Enter] to continue" readEnterKey
       ;;
   esac
done
 
1 members found this post helpful.
Old 11-02-2012, 10:09 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
Please post your thread once and in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread should be closed because it is a duplicate of http://www.linuxquestions.org/questi...se-4175435231/.
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] need answer of following few questions... raj.knd Linux - Newbie 8 01-25-2011 02:47 AM
Please answer for this questions.... infovijay Linux - General 1 10-31-2009 07:42 AM
Yast run in command line question raynet SUSE / openSUSE 1 02-21-2005 02:03 AM
Two questions I never get an answer to J_Szucs Linux - General 5 04-24-2004 12:22 AM


All times are GMT -5. The time now is 08:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration