I want to only have a process called if there actually is a STDERR present, but I don't know how to evaluate if one is actually present or not. This code:
errtest() {
kubectl get namespace -A
kubectl get namespace -A 2> >(echo "why am I here")
}
> errtest
Output:
NAME STATUS AGE
2c74fd3b89e64077afd34d8ab8af4f09 Active 10d
845d1f1c71ed42c8b9e4c780992a95c0 Active 367d
why am I here
NAME STATUS AGE
2c74fd3b89e64077afd34d8ab8af4f09 Active 10d
845d1f1c71ed42c8b9e4c780992a95c0 Active 367d
Obviously the first time shows that the output doesn't have any error, so the primary question is, why is "why am I here" showing? That seems counterintuitive.
The secondary question is, in this case, how could I identify the STDERR so that I can work on context? Something like:
kubectl get namespace -A 2> >(if [[ -z STDERR ]]; then echo "there is an error"; fi)
ifne
. Can you take it from here? – Kamil Maciorowski Apr 22 '22 at 17:38ifne
in the process substitution – muru Apr 22 '22 at 17:39read -t 0 dummy
(since bash is already used in the question) – A.B Apr 22 '22 at 17:46