DistributedNetworks DistributedNetworks

Unix Commands  «Prev  Next»

Identifying common errors -Exercise

Identifying common Syntax Errors

Objective: Correct syntax errors in a given script

Exercise scoring

This exercise is graded and worth 12 points.


In this exercise, make as few changes as possible to fix the script below. Do not rewrite the code; just fix the problems with the existing code. This script is called summation and it adds up all the numbers up to and including the number your user enters. For example, if the user enters 3, the script adds up 1 + 2 + 3. If the user enters 4, it adds up 1 + 2 + 3 + 4. #! /bin/sh total = 0 echo How many numbers do you want to add up? (or q to quit) \c"
read $num 
while ["$num" < one "q" ) 
total=`expr $total + $num num=`$num + 1` 
echo "The total is $total"


The script contains multiple syntax errors and one logic error.

Submitting your exercise

Paste your answer into the textbox below and press the Submit button.