例如,这一行失败:
$ nohup for i in mydir/*.fasta; do ./myscript.sh "$i"; done > output.txt&
-bash: syntax error near unexpected token `do
正确的方法是什么?
因为 'nohup' 需要一个单字命令及其参数 - 而不是 shell 循环结构。你必须使用:
nohup sh -c 'for i in mydir/*.fasta; do ./myscript.sh "$i"; done >output.txt' &
你可以在一条线上做,但你可能也想明天做。
$ 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 &
对我来说,乔纳森的解决方案没有正确重定向到 output.txt。这个效果更好:
nohup bash -c 'for i in mydir/*.fasta; do ./myscript.sh "$i"; done' > output.txt &