如何在stderr上打印而不使用/ dev / stderr [英] How to print on stderr without using /dev/stderr

查看:282
本文介绍了如何在stderr上打印而不使用/ dev / stderr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

linux命令脚本如何在每次不使用> / dev / stderr 时打印警告或错误消息?

How can a linux command script print warnings or error messages without using >/dev/stderr each time?

这应该很简单,但我不明白。

This should be simple but I don't get it.

您可以发布一个简单的示例吗?

Can you post a simple example?

推荐答案

标准错误,使用写入标准输出(如 echo printf )并将输出重定向到文件描述符2。

To print to standard error, use a command that writes to standard output (like echo or printf) and redirect the output to file descriptor 2.

echo "This goes to standard output"
echo "This goes to standard error" >&2

这是文件描述符复制操作符最常见的用法,前面的数字(如果省略,则为1)由以下数字表示的描述符的副本。

This is the most common use of the file descriptor duplication operator, which makes the descriptor indicated by the preceding number (or 1 if omitted) a copy of the descriptor indicated by the following number.

这篇关于如何在stderr上打印而不使用/ dev / stderr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆