Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


Closed Thread
  Search this Thread
Old 03-03-2018, 12:34 PM   #1
LQ Newbie
Registered: Mar 2018
Location: NC
Distribution: CentOS, Mint 18.4, Fedora 27 and Solus
Posts: 6

Rep: Reputation: Disabled
Newbie Question - Shell Script While Loop Based on User-Input

I'm trying to get this script to include a while loop that queries the user to choose if they want to run it again or not. I'm not sure what the while loop construct should be or where in the script to put it.

Here's the meat of the program:

# Bash shell script to calculate student average
# Usage: ./    

# Declare some integer type variables
echo -n "Do you wish to enter another set of scores? (y/n) "
while [ "$CHOICE" != "n" ]
declare -i test1
declare -i test2
declare -i test3
declare -i test4
declare -i lab
declare -i sum

    echo "=================="
    echo "Grade Calculator  "
    echo "=================="
    read -p "Enter first name: " firstname
    read -p "Enter last name: " lastname
    read -p "Enter test score 1: " test1
    read -p "Enter test score 2: " test2
    read -p "Enter test score 3: " test3
    read -p "Enter test score 4: " test4
    read -p "Enter lab score: " lab


    if [ $average -ge 90 ]; then
    elif [ $average -ge 80 ]; then
    elif [ $average -ge 70 ]; then
    elif [ $average -ge 60 ]; then
    elif [ $average -le 60 ]; then
    echo "Course Grade: "$grade
    echo "Grade results . . ."
    echo "Student name: $firstname $lastname"
    echo "Total points: $sum"
    echo "Course average: $average"

    case $grade in
    A) echo "An 'A' represents superior course work."
    B) echo "A 'B' represents above average course work."
    C) echo "A 'C' represents average course work."
    D) echo "A 'D' represents below average course work."
    F) echo "An 'F' represents failing course work."
Old 03-03-2018, 10:28 PM   #2
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,666
Blog Entries: 6

Rep: Reputation: 2531Reputation: 2531Reputation: 2531Reputation: 2531Reputation: 2531Reputation: 2531Reputation: 2531Reputation: 2531Reputation: 2531Reputation: 2531Reputation: 2531
Please post your thread only once, 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 is being closed because it is a duplicate of this one.

Last edited by astrogeek; 03-03-2018 at 10:30 PM. Reason: once
1 members found this post helpful.

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] How to make a WHILE loop iterate over script until user input stops hebruiser Programming 3 03-05-2018 08:31 PM
hang script (trap) for user input in a loop with ctrl and any other letter pedropt Programming 4 12-10-2017 04:06 PM
[SOLVED] A question about for-loop in shell script thomas2004ch Linux - Software 4 10-30-2013 05:12 AM
Shell script user input tuckermaddox Linux - Newbie 5 08-12-2004 03:14 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:27 PM.

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