ardevd
ardevd

Reputation: 3407

Comparing string length

Trying to check if the length of a string is less than 7. I figured the following code should work just fine, but its not. Whats wrong?

if [ ${#certid} -lt 5] ; then
echo "[!] invalid ID"
exit
fi

Upvotes: 0

Views: 1235

Answers (1)

Ivaylo Strandjev
Ivaylo Strandjev

Reputation: 70929

You have several problems:

  1. you compare to 5 not to 7
  2. you print that an id is invalid if the length of certid is less than 5 instead of if it is longer than 5. Use gt instead of lt
  3. you miss a space before the closing ]

Upvotes: 2

Related Questions