Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kellah

macrumors regular
Original poster
Apr 29, 2007
121
0
East Lansing, MI
I found a bunch of posts on the internet about this but I'm still running into problems. Here's my goal of my script: check to see if my external hard drive is mounted. (It's called "Files") and then use ditto to copy all the files over. I've got ditto to work but now that I'm trying to do an if-else statement it has problems.

Here's what I've got:

Code:
#!/bin/sh                                                                       

if (-e $d/$f) then
    ditto -V /Users/andrew/Misc /Volumes/Files/Backup
else
    echo "External drive not mounted!"
endif

When I try to run the script I get this error:

./backup: line 9: syntax error: unexpected end of file

What am I doing wrong?
 

numero

macrumors regular
Jul 23, 2002
106
3
OR
I believe you want something like this:

Code:
#!/bin/sh

if [ -e $d/$f ]
then
    ditto -V "/Users/andrew/Misc /Volumes/Files/Backup"
else
    echo "External drive not mounted!"
fi

You will need the quotes around the path name if there is a space after "Misc". You won't if there isn't.

In the "if" statement, the spaces around the square brackets are very important. They don't like anything touching them. Very "separatist" of them. :)
 

aross99

macrumors 68000
Dec 17, 2006
1,541
1
East Lansing, MI
The syntax you are using is from the C-shell (csh) or Korn shell (ksh), not the Bourne shell (sh) that you have specified on the first line.

If you specify "sh" on the 1st line, you need to use the square brackets, etc as the poster above has specified. Try changing line 1 to specify csh or ksh if you want to use your original syntax...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.