bash - nohup 和 sed,重定向 stderr 和 stdout

标签 bash unix sed pipe nohup

在我的服务器上 nohup sleep 1 > nohup.out & 没有提供帮助信息。很好。
在我的笔记本电脑上运行相同的命令,我得到:nohup: ignoring input and redirecting stderr to stdout。虽然该命令仍然运行并正确完成,但我不明白为什么我的两台机器在报告此消息时存在差异。不过,幸运的是,我可以通过简单地将 stderr 和 stdout 重定向到一个文件来解决我笔记本电脑上的这个问题:nohup sleep 1 &> nohup.out &

所以....我想做的是在我的笔记本电脑上执行一个更有用的命令:

以下在我的服务器上工作正常,没有报告任何消息:
nohup ls -1 *.txt | sed -e "s%\(.*\)%/home/user/scripts/script.pl -find\1 %"| sh > nohup.out &

这行代码“nohups”将文件的管道列表“nohups”到 sed 中,在那里它们通过 script.pl 连续运行并在 shell 中执行。 script.pl 将数据打印到多个文件,并将一些信息打印到标准输出。我通过将其写入名为 nohup.out

的文件来捕获此信息

现在,当我在笔记本电脑上运行这个单行程序时,我得到 nohup: ignoring input and redirecting stderr to stdout。这是预期的(但出于我不知道的原因)。但是当我修改该行以重定向 stderr 和 stdout 时:
nohup ls -1 *.txt | sed -e "s%\(.*\)%/home/user/scripts/script.pl -find\1 %"| sh &> nohup.out &

我仍然收到消息 nohup: ignoring input and redirecting stderr to stdout

如何修复我的 one-liner,使其在笔记本电脑上运行时不会收到显示的消息?

最佳答案

我这可能对你有用:

nohup ls -1 *.txt 2>/dev/null | .....

原因是 nohupstderr 发出警告消息,因此将 stderr 指向无处 2>/dev/null 抛弃它。

关于bash - nohup 和 sed,重定向 stderr 和 stdout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8426392/

相关文章:

linux - 如何对 linux bash * 字母数字字符串进行排序

unix - 如何对字符串中的字符进行排序?

python - 如何使用 Python 将自定义 linux stdout 粘贴到 JSON 中?

linux - 当 -i 不可用时在 sed 中模拟 -i 标志

linux - 一些文本替换问题。请指教

bash - 使用 AWK 将文本文件中的每个单词换行

arrays - 目录中所有文件的数组,除了一个

bash - 从 bash 脚本设置 JAVA_HOME

c - 什么是 `S_ISREG()` ,它有什么作用?

linux - Sed:添加到特定行的末尾