-1

Can someone please explain to me why I'm getting 'command not found' on line 11 when I try and run the script?

#!/bin/bash
var="nef892na9s1p9asn2aJs71nIsm"

for counter in {1..40}
do
        var=$(echo $var | base64)
        if [[$counter -eq 35]]; then
                echo $var
        fi
done

Line 11 is: if [[$counter -eq 35]]; then

I've tried various indentations and removing the double brackets on the 'if' statement. I'm expecting the script to print out the 35th iteration of the 'var' variable. Thank you.

Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • 2
    Please paste your script at [shellcheck.net](http://www.shellcheck.net/) and try to implement the recommendations made there. – Cyrus Mar 23 '23 at 22:40
  • add spaces behind `[[` and before `]]`. – Wiimm Mar 23 '23 at 22:42
  • I added a duplicate link that explains `[]` since I can't find one specific to `[[]]`. If someone else know that, please let me know so I can add it to my list. – Barmar Mar 23 '23 at 23:00
  • for future reference: post the entire error message in your question; in this case ... line 11 is the `done` (in the code you've provided); for the code in the question the complete error message would look something like: `script.sh: line 7: [[1: command not found`; with the complete error message most of us here at SO are going to know immediately what the issue is – markp-fuso Mar 23 '23 at 23:10
  • `[` and `[[` are commands, not part of the syntax, so you need to include a space between them and their arguments. – Sammitch Mar 24 '23 at 00:00
  • Always pay attention to the exact wording of the error message. I'm pretty sure that the message does not just say just _command not found_, but i.e. _bash: **[[1**: command not found_, and the `[[1` in the message tells you what's going wrong. – user1934428 Mar 24 '23 at 07:14

1 Answers1

0

shellcheck.net did indeed find that I needed to add spaced behind [[ and before ]]

Thank you for your replies.