Syntax help

Joined
Apr 23, 2012
Messages
2
Reaction score
0
Points
1
#!/bin/bash

bash -c if [ system_profiler SPAirPortDataType | grep theprinceandthepauper: ] = theprinceandthepauper;
then
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.AppleFileServer.plist;
sudo launchctl load -w /System/Library/LaunchDaemons/smbd.plist;
echo "connected to princeandpauper sharings settings"
elif [ system_profiler SPAirPortDataType | grep eduroam: ] = eduroam;
then
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.AppleFileServer.plist;
sudo launchctl unload -w /System/Library/LaunchDaemons/smbd.plist;
echo "connected to eduroam and settings applied"
else
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.AppleFileServer.plist;
sudo launchctl unload -w /System/Library/LaunchDaemons/smbd.plist;
echo "connected to unknown"
fi

im getting an error everytime i run this. Some silly syntax cant figure out what it is?

[: -c: line 1: syntax error: unexpected end of file
grep: ]: No such file or directory
grep: =: No such file or directory
grep: theprinceandthepauper: No such file or directory
homesharing.sh: line 4: syntax error near unexpected token `then'
homesharing.sh: line 4: ` then'
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
There are a few things to note:

1. Equality statements use two equal signs, not one (you use one equal sign for assignment). As it is right now, the first line of your if statement is using only one when you want two.
2. You've got unnecessary semi-colons at the end of your statements. You only need the semicolon if you have more than one statement on a line. This however will not be causing the error.
3. Why are you executing bash on the first line?
4. Everything after "if" and before "then" needs to be in the square brackets.

Start there. Most of the issues have to do with how you've written your if statement. Take a look here for some reading.

You can also use the following as a template:
Code:
#!/bin/bash
name="vansmith"
if [ $name == "vansmith" ]; then
        echo "Hello"
fi
In that case, the variable name does equal vansmith so Hello is echoed.
 
OP
M
Joined
Apr 23, 2012
Messages
2
Reaction score
0
Points
1
Thanks a ton for the web link! very useful.
1.Thanks silly error
2.old habits die hard i guess :)
3.well running it in bash as system_profiler SPAirPortDataType is not a file or directory
4.ahh didnt know!

my knowledge of bash commands is as you can see quite zilch. Any suggestions as to how to run this?? Fixed most of the syntax but still no dough :(
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Yeah, the if statement is a bit odd. What exactly are you trying to accomplish here? It looks like you're trying to determine what network you're connected to and then continuing accordingly. If that's true, you're missing one important point - you're searching for "theprinceandthepauper:" and asking if it's equal to "theprinceandthepauper" which it never will be since that colon matters. ;)
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top