if script error: integer expression expected

Hi, i am making a simple program with a optional -t as the 3rd parameter.
Submit course assignment -t dir

In the script, i wrote:

#!/bin/bash
echo "this is course: ${1}"
echo "this is assignment #: ${2}"
echo "late? : ${3}"
if [ "${3}" -eq "-t" ] then
	echo "this is late"
fi

but this gives me a

: line 5: [: -t: integer expression expected

error.

Could someone give me a hand? thanks

"-eq" is for comparing integers. Use "=" instead:

if [ "${3}" = "-t" ] then

BTW, please use "CODE" tags when posting something like a script. It makes it much easier to read.

1 Like

thank you

CA_RELEASE has a value of 6. I need to find that this is a numeric value. if not error.

source $CA_VERSION_DATA
if [ $CA_RELEASE -ne [0-9]* ]
then
logger -p $DESGNLOG "CA_RELESE $CA_RELEASE is invalid"
exit -1
fi

+ source /etc/ncgl/ca_version_data
++ CA_PRODUCT_ID=samxts
++ CA_RELEASE=6
++ CA_WEEK_NO=7
++ CA_COMPILE_NO=3
++ CA_MNCL_ID=0
+ '[' 6 -ne '[0-9]' ']'
/usr/sbin/delete_old_patch: line 21: [: [0-9]
: integer expression expected

How to resolve this? Please help