1

I try executed some like this

#!/bin/bash
${postid=41930}
while ${postid} < 42000;
do
 `node title.js ${postid}`
  ${postid} = ${postid} +1;
done

I have this error:

: command not found30
run.sh: line 8: syntax error: unexpected end of file

$ echo $SHELL
/bin/bash
$

From man sh

while *list*;do *list*;done

sh version 3.2

4 Answers 4

2

There are several places in your script needs to be fixed:

  1. As chepner said you can't assign value to an evaluated result like ${postid}, instead use postid directly in the left hand side of your assignment

  2. There should be some invisible characters in your script. Try to run dos2unix myscript.sh or try hand typing the the following code into an new file

https://gist.github.com/1651190

Sign up to request clarification or add additional context in comments.

1 Comment

Big thanks for your solutions. I must use vi :set ff=unix . And know all worked!!!
2

Another quick way, using only bash features is:

#!/bin/env bash
for postid in {41930..41999} ; do node title.js ${postid} ; done

References: http://www.gnu.org/software/bash/manual/bashref.html#Brace-Expansion

3 Comments

bc-c8-d8-eb-65:googlecache macbookpro$ sh run.sh run.sh: line 3: syntax error: unexpected end of file
Except if there are hidden characters in you file, I don't know what is wrong. Did you hand-type the code?
I'm surprised you had to do that in the first place. It should work out of the box if the file was created on your Mac. Or did the file originally come from another editor? Or did you copy a .vimrc from somewhere else? This could explain the problem. Anyhow, I'm glad you found your problem :)
1

Probably, you want

for((postid=41930;postid<42000;++postid)) do
 node title.js $postid
done

2 Comments

#!/bin/bash for((postid=41930;postid<41940;++postid)) do node title.js $postid done $ sh run.sh 'un.sh: line 2: syntax error near unexpected token do 'un.sh: line 2: for((postid=41930;postid<41940;++postid)) do
@v.tsurka, the question is tagged bash, not sh.
1

The other answers are probably what you want to use. FYI, here's where your errors came from.

${postid=41930}

To assign 41930 to posted, just use postid=41930. Note there are no spaces around the equals sign!

while ${postid} < 42000;

The {} around postid are optional; $postid works just as well.. You do need to wrap that conditional expansion in a command, as the while loop can't use a bare expression. Something like while [ $postid < 42000 ];. Note that in this case, you must have spaces separating the [ and ] from the rest of the expression.

do
    `node title.js ${postid}`
    ${postid} = ${postid} +1;

In order to assign a value to a variable, bash does not allow spaces around the equal sign. With spaces, it interprets this line by expanding $postid and treating that as a command to run, with = as the first argument. Use postid=$postid + 1;. On the left, no dollar sign is needed, as you are not expanding the value of a variable, but assigning to a name. On the right, you need the dollar sign to get the value of posted.

done

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.