例如,此行失败:

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

正确的方法是什么?

有帮助吗?

解决方案

因为“ nohup”期望单词命令及其参数,而不是壳循环构造。您必须使用:

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 &

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top