Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Im trying to run this shell script that is supposed to do this:

  • This script uses the softwareupdate program on OSX to automatically check for updates and install them. It also logs all updates to the /Library/Management/update.log file.

  • It first checks to see if there are any users logged in, and if so, logs the user in the log file and ends.

  • If there is no user logged in, it updates the computer, logs the information, and reboots.

I keep getting this error: line 9: syntax error near unexpected token `fi' line 9: `fi'

here is the script:

users1=$(echo "${#users}")
if [ $users1 -lt 1 ]    
date >> /Library/Management/update.log && /usr/sbin/softwareupdate -aiv >> 
/Library/Management/update.log && /sbin/reboot    
date >> /Library/Management/update.log && echo "Logged in users: " >> 
/Library/Management/update.log && echo $(users) >> /Library/Management/update.log    

Any ideas?

share|improve this question
Try #!/bin/bash instead of !/bin/sh. I have been told that there may be problem if the intended shell is not target, or the she-bang is not properly used. Especially if you intend to make it on auto-running scripts like corn-jobs (or some mac-os equivelent). – Abhinav Kulshreshtha Feb 27 '13 at 18:58
it does have the # but for some reason when I typed it into this page it wouldnt show up. – Ulysses Aguilar Feb 27 '13 at 21:49
What about using bash instead of sh. Try it, #!/bin/bash. I never used a real MAC but a few months on hakintosh, I know that zsh or csh is mostly default shell on it. On linux default is bash. – Abhinav Kulshreshtha Feb 28 '13 at 19:44
Woah! Thanks for pointing out this awesome CLI tool softwareupdate. Never knew about it. – kalaracey Mar 5 '13 at 3:23

The lines that start with date are missing line continuation characters. Replace them with something like this:

date >> /Library/Management/update.log && /usr/sbin/softwareupdate -aiv >> \
/Library/Management/update.log && /sbin/reboot    
share|improve this answer
I still get the same error – Ulysses Aguilar Feb 28 '13 at 16:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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