Answer the question
In order to leave comments, you need to log in
How to redirect stderr to bash via a function?
Good day,
There is, for example, a piece of code like this:
#! /bin/bash
error_action () {
echo "Failed! Check $ERR_LOG"
exit 1
}
apt-get install -y build-essential linux-headers-$(uname -r) >/dev/null || error_action
echo
, and nothing more.
Answer the question
In order to leave comments, you need to log in
This option is not suitable. The matter is that the redirection has to be in function. The script is quite voluminous, it 2>/tmp/error.log
would not be entirely rational to write it separately for all commands.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question