4

I use RaspberryPi 3. I would like to make it a hotspot if it can't find RaspbarryPi 3 auto wifi hotspot if no internet. The tutorial shows a code to edit rc.local file.

Please find my code of rc.local file below: http://pastebin.com/3mRXHCUG

When I debug the file, it shows error at line 39 as " Syntax error: "(" unexpected"

The code of line 39 is as follow:

ssids= ("Bhavik","iBall-Baton")

So RaspberryPi always crates hotspot no matter if the specified Wifi connections are available.

Kindly help me. Thanks.

  • Have you tried using square or curly braces instead of parentheses? – anonymous2 Jan 30 '17 at 19:04
  • Yes. they also don't work – HarshIT Jan 30 '17 at 19:10
  • Try ssids[0]="Bhavik"; ssids[1]="iBall-Baton". Does that work? – anonymous2 Jan 30 '17 at 19:14
  • No it does not work. – HarshIT Jan 30 '17 at 19:24
  • I just got the problem! You forgot to change your top line from #!/bin/sh to #!/bin/bash! BTW, a mistake I have made dozens of times... :) – anonymous2 Jan 30 '17 at 19:49
1

The issue is the way you are attempting to define your array. Basically, rc.local is written in bash scripting, and defining an array as

ssids= ("Bhavik","iBall-Baton")

isn't bash; it won't work. If you want to define the array manually, define it this way:

ssids[0]="Bhavik";
ssids[1]="iBall-Baton";

Then your code ought to work.

  • I face error saying, /etc/rc.local: 39: /etc/rc.local: ssids[0]=Bhavik: not found /etc/rc.local: 40: /etc/rc.local: ssids[1]=iBall-Baton: not found /etc/rc.local: 42: /etc/rc.local: Bad substitution – HarshIT Jan 30 '17 at 19:24
  • Wait, did you put Bhavik and iBall-Baton in quotes? It looks like the code is trying to substitute in values from non-existent variables. Try putthing them in quotes. – anonymous2 Jan 30 '17 at 19:26
  • Sorry I could not understand the last comment. Did you mean to put in single quote ? – HarshIT Jan 30 '17 at 19:28
  • @HarshIT, no, I meant, did you put in ssids[0]="Bhavik"; or ssids[0]=Bhavik;? Because you'll need the quotes in there, otherwise bash looks at Bhavik as a variable. – anonymous2 Jan 30 '17 at 19:28
  • I put ssids[0]="Bhavik"; – HarshIT Jan 30 '17 at 19:29
0

I just noticed a remarkably simple issue: You forgot to swap out the line

#!/bin/sh

for the line

#!/bin/bash

This means that the script is using the sh coding rather than the powerloaded sh scripting called bash. Your array should work any way you define it if you have your script defined correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.