为什么不能将 Unix Nohup 与 Bash For 循环一起使用?
- 2024-11-07 08:55:00
- admin 原创
- 171
问题描述:
例如此行失败:
$ nohup for i in mydir/*.fasta; do ./myscript.sh "$i"; done > output.txt&
-bash: syntax error near unexpected token `do
正确的做法是什么?
解决方案 1:
因为 'nohup' 需要单个单词命令及其参数 - 而不是 shell 循环构造。您必须使用:
nohup sh -c 'for i in mydir/*.fasta; do ./myscript.sh "$i"; done >output.txt' &
解决方案 2:
对我来说,Jonathan 的解决方案无法正确重定向到 output.txt。这个方法效果更好:
nohup bash -c 'for i in mydir/*.fasta; do ./myscript.sh "$i"; done' > output.txt &
解决方案 3:
您可以在一行中完成此操作,但您可能还想在明天完成此操作。
$ 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 &
相关推荐
热门文章
项目管理软件有哪些?
热门标签
云禅道AD