Bash: “command not found” in IF statement

This blog post is about a situation where writing an IF THEN ELSE statement with variables fails with something like

./ line 26: [[1: command not found

This was in a script called scalePREPROD that scaled app services if they were not a certain value – so I am checking to see IF they are a value of 15 and if they are not then scale up to 15.


You need a space in the IF statement when variables are used.

The code looked something like this:

for i in "${appServiceArray[@]}"; do
appcapacity=<bash query to check app services>
[[$appcapacity -ne $scaleAPPWorkersUp]];
<stuff to do>
<echo something back that we're all good>

So in the example above – I wanted to see if for my array of 6 app services ${appServiceArray[@]} any were not equal to a value of $scaleAPPWorkersUp.

To fix it I just needed to put a space so:

[[$appcapacity -ne $scaleAPPWorkersUp]];


[[ $appcapacity -ne $scaleAPPWorkersUp ]];

Pretty easy fix.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s