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