Stupid shellscript problem in MacOS X Snow Leopard...

slugg

Diamond Member
Feb 17, 2002
4,723
80
91
Error I'm getting:

'/exeme_binarize.sh: line 1: syntax error near unexpected token `
'/exeme_binarize.sh: line 1: `for src in *.pgm;


First two lines of the shellscript:


for src in *.pgm;
do


... what?? I don't understand the problem... Thanks in advance for your help. :)
 

Phantomaniac

Senior member
Jan 12, 2007
268
0
76
I dont know how scripting in OSX differs from Linux but you shouldn't need a semicolon at the end of the first line since its followed by a newline.

Post the rest of the script.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Do you literally have the `` marks around the for loop?
Do you have a #! line at the top telling it which interpreter to use?
 

slugg

Diamond Member
Feb 17, 2002
4,723
80
91
Here's the whole script, as-is:

for src in *.pgm;
do
# set target file name;
tgt=`./images1procesed/$src`
echo converting $src to $tgt;
# run "binarize" function with threshold=100;
iptool binarize $src $tgt 100
done




... So no, there's no #! line, and I don't have quotes around the for loop. Removing the first semicolon, I get this error:


'/exeme_binarize.sh: line 2: syntax error near unexpected token `do
'/exeme_binarize.sh: line 2: `do



I'm utterly confused. Why wouldn't this work? Is it some quirk about OS X?
 

Phantomaniac

Senior member
Jan 12, 2007
268
0
76
Looks like you still need an interpreter line: #!/bin/bash or #!/bin/sh

Also remove every semicolon. You shouldn't need those unless you are putting multiple statements on the same line.

You might also want to try using quotes instead of backticks for the statement assigning a file path to a variable.
 
Last edited:

slugg

Diamond Member
Feb 17, 2002
4,723
80
91
Looks like you still need an interpreter line: #!/bin/bash or #!/bin/sh

Also remove every semicolon. You shouldn't need those unless you are putting multiple statements on the same line.

You might also want to try using quotes instead of backticks for the statement assigning a file path to a variable.

"bad interpreter: No such file or directory" for both.

Quotes versus backticks haven't made a difference yet; it doesn't get past the first line of the code. :(
 

Phantomaniac

Senior member
Jan 12, 2007
268
0
76
"bad interpreter: No such file or directory" for both.

Quotes versus backticks haven't made a difference yet; it doesn't get past the first line of the code. :(

My experience with OSX is virtually non-existent but I figured I'd give it a try. You may want to find a Mac forum at this point.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
"bad interpreter: No such file or directory" for both.

Quotes versus backticks haven't made a difference yet; it doesn't get past the first line of the code. :(

If OS X doesn't store bash at /bin/bash, then where is it?
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,695
4,657
75
If OS X doesn't store bash at /bin/bash, then where is it?
In other words, use '#' followed the the result of `which bash`.

Edit: You can use the result of this command for the first line:
echo "#`which bash || which sh`"