The code is exactly the same, except one uses a variable. What is going on? I spent 2 hours trying to read a file and list line by line and found out variables are not working at all?
Are you trying to run the lines directly in the Terminal? If yes then each line has its own scope, the variable $ssids you declared on the first line no longer exists on the 2nd line.
If running from the Terminal command line, put both lines in a { ... } block. After the opening { you can put as many lines as you want, and close with a final }. The block will then be treated as one single scope.
Alternatively, create a script under /system script then use /system script run to run it.
Maybe if you'd spent those two hours reading the documentation, however poor it may be,
you'd surely have figured out the problem yourself... [as @CGGXANNX wrote]
Each line written in the terminal is treated as local scope
Well, there is a difference between local and global variables. If you'd use global in first example its scope, it would have worked.
As @rextended points out, local variable scope defined to the current CLI line:
So the {} block is what create a new scope, but that is still part of the same CLI line.
Now local scope is valid through out a /system/script (or scheduler). So to test a script at CLI, you do need the {} to emulate same scoping as /system/script would use.