Reputation: 452
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
Upvotes: 1
Views: 516
Reputation: 14393
There are several places in your script needs to be fixed:
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
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
Upvotes: 2
Reputation: 532268
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
Upvotes: 1
Reputation: 329
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
Upvotes: 2
Reputation: 143279
Probably, you want
for((postid=41930;postid<42000;++postid)) do
node title.js $postid
done
Upvotes: 1