The idea was to forward STDOUT and STDERR to a variable/array, to create the possibility to log it in a file. Especially STDERR should be logged.
Thks to TheConstructor, I found a solution I thougth it should work in every case ...
<Store / Capture stdout and stderr in different variables (bash)>
My bash doesn't support :
readarray
typeset: t_err
my version of bash :
bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin15)
Copyright (C) 2007 Free Software Foundation, Inc.
my thought :
function CMD() {
unset t_std t_err
eval "$( ($1 ; $1 >&2) 2> >(readarray -t t_err; typeset -p t_err) > >(readarray -t t_std; typeset -p t_std) )"
}
CMD "cp x.txt new_x.txt"
CMD "nocommand new_x.txt"
these are the errors given by the bash :
./test_files.sh: line 61: readarray: command not found
./test_files.sh: line 61: typeset: t_err: not found