如何在Bash脚本中指定stderr文件?

huangapple go评论48阅读模式
英文:

How to specify the stderr file in the bash script?

问题

我有一个简单的bash脚本:

#!/bin/bash

一些bash代码....

并且在启动它时:

./myscript.sh

我想将错误重定向到error.err文件,并且我想在myscript.sh文件中指定该文件的名称(这里是:error.err)。

(所以我想避免这样做:./myscript.sh 2>error.err

这可行吗?

非常感谢

英文:

I have a simple bash script:

#!/bin/bash

Some bash code....

And when starting it with:

./myscript.sh

I would like to redirect the error into error.err file, and I would like to specify the name of this file (here: error.err) inside myscript.sh file.

(so I would like to avoid doing: ./myscript.sh 2>error.err)

Is it possible

Thanks a lot

答案1

得分: 0

exec 2>error.err

英文:

Just prepend the following line to the script

exec 2>error.err

huangapple
  • 本文由 发表于 2023年3月31日 22:54:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75899940.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定