Use subshell for output redirection security.

If a command were to be something like `echo a; echo b;` redirection
would only happen on the `echo b;` messing up everything.
This commit is contained in:
redxef 2022-11-22 00:43:16 +01:00
parent 5966744e34
commit 4b7e717da1
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921

View file

@ -27,16 +27,16 @@ stdout_file="${STDOUT_FILE}"
# dont write anything to stdout, since that would get appended to the tar file
if [ "$stderr_file" = "-" ] && [ "$stdout_file" = "-" ]; then
# redirect stdout to stderr
${COMMAND} 1>&2
( ${COMMAND} ) 1>&2
elif [ "$stderr_file" != "-" ] && [ "$stdout_file" = "-" ]; then
# stderr to file, stdout to stderr
( ${COMMAND} 2>"$stderr_file" ) 1>&2
( ( ${COMMAND} ) 2>"$stderr_file" ) 1>&2
elif [ "$stderr_file" = "-" ] && [ "$stdout_file" != "-" ]; then
# stdout to file
${COMMAND} 1>"$stdout_file"
( ${COMMAND} ) 1>"$stdout_file"
else
# both files specified
${COMMAND} 1>>"$stdout_file" 2>>"$stderr_file"
( ${COMMAND} ) 1>>"$stdout_file" 2>>"$stderr_file"
fi
)