-1

so i am new to bash scripting and trying to setup my first conditional block. I am using a shell script to get a JSON response and when the returned item is 0 i want it to do something.

QUEUE_SIZE=$(curl url | jq '.items | length')

if ["$QUEUE_SIZE" -eq "0"]
then
   echo "Hey this is cool!!"
fi

When i run the above script, i get the following error: line 3: [0: command not found

Can someone please correct what i'm doing wrong? Thank you for the assistance.

TreeHuggerRick
  • 402
  • 2
  • 5
  • 18

1 Answers1

0

Minor revision:

#!/bin/bash

QUEUE_SIZE=$(curl url | jq '.items | length')

if [ "$QUEUE_SIZE" == "0" ]; then
   echo "Hey this is cool!!"
fi
Milag
  • 1,793
  • 2
  • 9
  • 8
  • Heyy!! Nice. Thank you, It worked – TreeHuggerRick Nov 30 '20 at 20:49
  • Use `=` not `==` -- the latter is not POSIX-specified and not guaranteed to work on all shells (and several `/bin/sh` implementations don't support it; we have questions from their users in our knowledge base). Even when your shell is known to be bash, better to be in the habit of writing more broadly-compatible code when there's no concrete benefit to be gained by doing otherwise. – Charles Duffy Nov 30 '20 at 21:00