#!/bin/sh
for i in {0..999}
do
if [$i lt 10]
then
nohup java BeginIndex ~actors/00{$i} ~/index_new/ > ~/results/actors_results/00{$i}.txt
echo "INDEXING ($i)th directory completed "
elif [$i lt 100]; then
nohup java BeginIndex ~/actors/0{$i} ~/index_new/ > ~/results/actors_results/0{$i}.txt
echo "INDEXING ($i)th directory completed "
else
nohup java BeginIndex ~/actors/{$i} ~/index_new/ > ~/results/actors_results/{$i}.txt
echo "INDEXING ($i)th directory completed "
fi
done
Can anyone tell me what's wrong with this script? do I need to do #!/bin/bash first? Also, can i nohup this script the way it's written or do I have to remove the nohup in the if-else statements? I don't really know all the syntax of if-else and for loops for bash... sorry if this is such a simple question. I appreciate the help!
Edit (posting an update from comments)
I'm trying to index a directory called actors, with 1000 subdirectories with files inside them. the java program will run, but it can't handle all the files in these 1000 directories (about 1.8million). I want to write a script that will do it subdirectory at a time.
I'm ssh'ing into a se开发者_JAVA技巧rver to do this, but it will take a while so I want it to not drop. I can't just run the java program on the whole directory, because it runs out of heap memory. It's not the most efficient java code, but I'm working on another solution to that problem while this script runs subdirectory-at-a-time.
The test command is definitely wrong.
Just remember "["
in bash is a command, not a syntax. It expects the string "]"
as the last argument. This is why spaces are required before and after them. (Semicolon is OK, because it is a part of the syntax)
Also, as Kerrek pointed out, the comparation operator is -lt
not lt
.
The test functions need a hyphen in front of the option:
if [ $i -lt 10 ] ; then
# ....
fi
Note that [
is just an ordinary command, usually in /usr/bin/[
, and it has to be treated as such.
精彩评论