It is quite straightforward to check if a single command returned exit code 0. However, I'm not sure what to do if I use echo with a command. For example, in this case, program I want to test definitely returns non-zero exit code, but it looks like bash looks at echo's exit code instead, which is 0:
if echo "something" > exit 42; then
echo "OK"
else
echo "NOT OK"
fi
It makes impossible to check if a program which requires interactive input returned non-zero exit code. How can I fix that and get the exit code of the program I'm echoing something to?
if echo "something" > ./mybinary; then
exit
.