Sponsored Content
Top Forums UNIX for Beginners Questions & Answers If condition is not working and getting error Post 302990167 by Torrid on Monday 23rd of January 2017 09:01:41 AM
Old 01-23-2017
If condition is not working and getting error

Hi Team,

If condition is not working properly and getting below error

Code:
# ./score1.sh
Enter your score [0-100%] ('q' for quit): 102
Enter your score [0-100%] ('q' for quit): q
./score1.sh: line 9: [: q: integer expression expected
Average is: 102%.
Exit.

Actual code

Code:
# Calculate the average of given number.
SCORE=0
AVERAGE=0
SUM=0
NUM=0
while true; do
echo -e  "Enter your score [0-100%] ('q' for quit): \c "
read SCORE;
if [ $SCORE -lt 0  -a $SCORE -gt 100 ]; then
echo "Give correct range "
elif [ $SCORE == q ]; then
echo "Average is: $AVERAGE%."
break
else
SUM=$[$SUM + $SCORE]
NUM=$[$NUM + 1]
AVERAGE=$[$SUM / $NUM]
fi
done
echo "Exit."


Thanks
Torrid.

Last edited by rbatte1; 01-23-2017 at 10:21 AM.. Reason: Added CODE tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If condition not working

Hi Gurus, I have shell script in which i have to check if time is between to possible value or not. For that i am using following line of code if then echo 'Found In Between' echo $ftime ... (5 Replies)
Discussion started by: MANISH KU
5 Replies

2. Shell Programming and Scripting

error in if-else condition

Hi.. Im using the following script to find whether the present day is monday or not. If it is monday it has to do a specific set of things. #!/bin/sh Present_Date=`date` LOAD_DAY=`date -d "$Present_Date" | cut -d " " -f 1` echo $LOAD_DAY if ;then echo "Monday" #statements;... (6 Replies)
Discussion started by: abala
6 Replies

3. Shell Programming and Scripting

wild card in if condition not working

Hi, I am using RHEL5. I have following if condition. if In the above condition, if the value of a contains word WARNING, it should match. i.e., WARNING_MESSAGE, CRITICAL WARNING, WARNING ALERT etc. it should match. For b, alert error, ALERT ERROR, ERROR IMMEDIATE ACTION REQUIRED, etc... (2 Replies)
Discussion started by: user7509
2 Replies

4. UNIX for Advanced & Expert Users

If condition and htm not working

checkSync() { CONNECT_STRING=TLDB61/TLDB61@TL10G SQLPLUS_SETTINGS="SET PAGESIZE 0 LINESIZE 1500 ECHO OFF TRIMS ON TAB OFF FEEDBACK OFF HEADING OFF" SQL_RESULT_SYNC_PMCM=`sqlplus -s ${CONNECT_STRING} << EOF ${SQLPLUS_SETTINGS} (SELECT... (2 Replies)
Discussion started by: madfox
2 Replies

5. Shell Programming and Scripting

Using ssh to transfer file not working inside if-condition

Hi all, ssh uname@remote_server 'cat /tmp/remote_file_name > home_dir/a512386/new/local_file_name' The above given command is working fine. but if i try to move the file only if exists in the remote server i.e) giving the same within if condition it executes but the file is not stored in my... (1 Reply)
Discussion started by: Shri123
1 Replies

6. Shell Programming and Scripting

Condition error!

Hi Guys, Can you please help me to check if my condition is correct. if && then if ; then # active SE_USERID_LUZON_5="A" elif ; then # not active SE_USERID_LUZON_5="D" ${ECHO_CMD}... (3 Replies)
Discussion started by: nikki1200
3 Replies

7. Shell Programming and Scripting

while condition error:

I'm trying to run following code: while do echo "Hello World" done but I'm getting error on first line: ./test: line 1: syntax error near unexpected token `(' can anyone please tell me who can i run this loop. Also please tell me what will be syntax of do while loop in case i... (11 Replies)
Discussion started by: kashif.live
11 Replies

8. UNIX for Dummies Questions & Answers

error in if condition

Hi All, I need to compare the header of the input files which can be comma demilited, tild(~) or Pipr(|) seperated file. I am comparing the file header by taking 1st row and comparing it with input row: Below is the actual code:(ksh script) if then echo $dat >>... (4 Replies)
Discussion started by: abhi_123
4 Replies

9. Shell Programming and Scripting

Error: if condition

please follow below code if ; then its giving me an error as "test1.sh: line 3: r=$(eval echo '$lck_'$TABLE != "") if can anyone tell me how to do inside if condition...with out use any variable.. TIA (6 Replies)
Discussion started by: gnnsprapa
6 Replies

10. Shell Programming and Scripting

If condition on shell not working , not sure what is the mistake I am doing?

I have a requirement to perform specific set of tasks based on server , So I want to have the condition(s) defined based on server. Here is the script I came up with and I have read multiple blogs and couldn`t find any mistake from my script. Can you guide on what I am overlooking here ? ... (2 Replies)
Discussion started by: Varja
2 Replies
tis_cond_destroy(3)					     Library Functions Manual					       tis_cond_destroy(3)

NAME
tis_cond_destroy - Destroys the specified condition variable. LIBRARY
Standard C Library (libc.so, libc.a) SYNOPSIS
#include <tis.h> int tis_cond_destroy( pthread_cond_t *cond); STANDARDS
None PARAMETERS
Address of the condition variable (passed by reference) to be destroyed. DESCRIPTION
This routine destroys the condition variable specified by cond. After this routine is called, DECthreads may reclaim internal storage used by the condition variable object. Call this routine when a condition variable will no longer be referenced. The results of this routine are unpredictable if the condition variable specified in cond does not exist or is not initialized. For more information about actions when threads are present, refer to the pthread_cond_destroy(3) description. RETURN VALUES
If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows: Successful completion. The object being referenced by cond is being referenced by another thread that is currently executing tis_cond_wait(3) on the condition variable specified in cond. (This error can only occur when threads are present.) The value specified by cond is not a valid condition variable. ERRORS
None RELATED INFORMATION
Functions: tis_cond_broadcast(3), tis_cond_init(3), tis_cond_signal(3), tis_cond_wait(3) Manuals: Guide to DECthreads and Programmer's Guide delim off tis_cond_destroy(3)
All times are GMT -4. The time now is 05:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy