Besides the fact that on a default OpenWrt there is not bash but ash, I don't spot any obvious error. As far as I can tell, all this is POSIX compliant. shellcheck also does not see any issue with your if statement.
In these type of errors, i always forget (or take as impossible) that someone using winscp or whatever only to transfer 10 words long file from PC to OWRT
There is a VI on OWRT, and it feels so natural to use it for 1-2KB scripts
I'm kinda offended by your post. I said I don't know Bash
If you want to stick with VI, Nano etc good for you. I never use VI for coding.
There's a reason why we have VSCode, IntelliJ, VStudio etc in these days.
You sound like an Assembly guy trying to humiliate C people.
RE: vi or vim; it is at least useful to know that i gets you into insert mode, with ESC you got back to "command mode" or how ever it is called, and with :wq you write and quit. Its fine to navigate with the arrow keys. It does not hurt to know at least this little bit. And yeah kidda lol you got hit by line encodings, I would have not guessed this, because half your script worked
I know vi and I use it time to time for just small edits.
But for programming? No function parameter hints, no autocomplete, no syntax highlighting etc. Hell no.