39

例如,这一行失败:

$ nohup for i in mydir/*.fasta; do ./myscript.sh "$i"; done > output.txt&
-bash: syntax error near unexpected token `do

正确的方法是什么?

4

3 回答 3

96

因为 'nohup' 需要一个单字命令及其参数 - 而不是 shell 循环结构。你必须使用:

nohup sh -c 'for i in mydir/*.fasta; do ./myscript.sh "$i"; done >output.txt' &
于 2010-06-23T05:24:23.240 回答
9

你可以在一条线上做,但你可能也想明天做。

$ cat loopy.sh 
#!/bin/sh
# a line of text describing what this task does
for i in mydir/*.fast ; do
    ./myscript.sh "$i"
done > output.txt
$ chmod +x loopy.sh
$ nohup loopy.sh &
于 2010-06-23T05:29:06.030 回答
9

对我来说,乔纳森的解决方案没有正确重定向到 output.txt。这个效果更好:

nohup bash -c 'for i in mydir/*.fasta; do ./myscript.sh "$i"; done' > output.txt &

于 2014-02-27T19:34:49.817 回答