簡體   English   中英

為什么我不能在Bash For-loop中使用Unix Nohup?

[英]Why can't I use Unix Nohup with Bash For-loop?

例如,此行失敗:

$ 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 &

對我來說,Jonathan的解決方案沒有正確地重定向到output.txt。 這個更好用:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM