Question:
Linux shell scripting if statement help please?
James Miller
2012-11-05 08:28:50 UTC
why wont this work: ??/

#!/bin/bash

#Date: 05/11/2012
#Author: James Miller

# This program will calculate the grade and display
# the letter grade of CST8102 class. The program will
# calculate only using integers

echo ""
echo "Please only enter integers only and no decimal numbers"

echo ""
echo "Enter assignment mark (0 to 40): "
read assignment


#error checking for assignment
if [$assignmen > 4] || [$assignment < 0];
then
echo "please re-enter grade: "
read assingment
fi

#echo "Enter test1 mark (0 to 15): "
#read test1
#echo "Enter test2 mark (0 to 15): "
#read test2
#echo "Enter Final Exam mark (1 to 30): "
#read exam
Four answers:
ratter_of_the_shire
2012-11-06 18:07:58 UTC
if (( [$assignment > 40] || [$assignment < 0] ));

then echo "Invalid assignment mark: $assignment" && exit

fi



# If you want to loop until a valid mark is entered, use the while syntax.
?
2016-12-26 11:25:42 UTC
i think of of you're complicated extremism and fundamentalism. The be unsleeping fundamentalism has earned a damaging connotation, yet became in user-friendly terms meant as a reaction to religious liberalism. An extremist must be somebody that shoots an abortionist indoors the call of life, a fundamentalist is somebody who insists on doing Christianity the way the scriptures say.
Liz
2012-11-05 08:59:23 UTC
if [$assignmen > 4] || [$assignment < 0];

# missing a t in assignment also..

# mind your whitespace in spite of what they tell you



if [ $assignment > 4 ] || [ $assignment < 0 ];
potatocouch
2012-11-05 08:39:02 UTC
< in bash is "-lt"

> is "-gt"


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...