homepage Welcome to WebmasterWorld Guest from 54.167.138.53
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
Bash conditional syntax error (Mac OS X)
pillsbur




msg:3918652
 5:50 pm on May 22, 2009 (gmt 0)

Hi,

I'm working on my first Bash conditional and don't understand why Terminal is reporting a particular syntax error. I have plenty of php and javascript experience, so I'm not new to conditionals.

Here's my script:
for user in $(ls /Users)
if [ "$user" != 'administrator' ] ; then
do
sudo cp -rf /Users/gpillsbu/Library/Preferences/com.apple.dock.plist /Users/$user/Library/Preferences/com.apple.dock.plist
sudo chown -hR $user /Users/$user/Library/Preferences/com.apple.dock.plist
fi
done

Here's the error:
./Update User Dock.sh: line 7: syntax error near unexpected token `if'
./Update User Dock.sh: line 7: `if [ "$user" != 'administrator' ] ; then'

I've tried several different syntax things like removing the quotes around $user, putting the 'then' statement on its own line, retyping the whole thing, etc.

What is an "unexpected token"?

FWIW, the script has worked fine before I tried to add the conditional.

Any help is appreciated!

Glenn

 

nalin




msg:3932867
 3:31 am on Jun 14, 2009 (gmt 0)

You need your conditional to be inside your for loop

for user in $(ls /Users)
do
if [ "$user" != 'administrator' ] ; then
...snip...

pillsbur




msg:3933601
 3:42 pm on Jun 15, 2009 (gmt 0)

Thanks!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved