Redirecting command output to a variable in bash fails June 7, 2023 by Tarik Maybe the output goes to stderr, not stdout? Try this: OUTPUT="$(sudo apache2ctl configtest 2>&1)"