【问题标题】:How to replace Linux Kernel error messages with my defined error messages?如何用我定义的错误消息替换 Linux 内核错误消息?
【发布时间】:2013-10-05 02:39:53
【问题描述】:

我创建了一个 shell,当我给 cp 命令提供错误数量的参数(例如参数不足)时,我会收到 Linux shell 错误消息,就像您输入 cp fork.c 时会收到的一样:

mysh> cp fork.c
cp: missing destination file operand after `fork.c'
Try `cp --help' for more information.

如何绕过此错误消息并打印我自己的错误消息,例如 Dude! this is an error

【问题讨论】:

  • 消息不是来自内核..

标签: c linux error-handling arguments kernel


【解决方案1】:
cp fork.c > /dev/null 2>&1 || echo "Dude! this is an error"

【讨论】:

  • 这是一个很好的答案!我真的很喜欢它!
【解决方案2】:

该消息是由cp 命令生成的,而不是由内核或外壳程序生成的。您需要自己重新实现 cp 命令,或者捕获并替换其输出以更改消息,但这些都不是真正适合 shell 做的事情。

【讨论】:

  • 如何捕获和替换每个命令的输出以更改消息??
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-22
  • 1970-01-01
  • 2022-11-19
相关资源
最近更新 更多