Control: rename -1 bash: output redirection is ineffective
Control: tags -1 moreinfo

On Sun, 24 Apr 2022 14:12:34 +0000 Mcgiwer <mcgi...@proton.me> wrote:
Package: bash
Serverity: serious

OS: Debian 11

Description:

I had found a strange issue in Bash: there is a problem with redirecting the 
output of some commands when executing them in the console.

I had attempted all variants (wroten as a template):

\`\`\`
\* command > file.txt
\* command >> file.txt
\* command 1> file.txt
\* command 2> file.txt
\* command 3> file.txt
\* command &> file.tx
\* command \| tee file.txt
\`\`\`

In every case the output was shown in the console and the file remained empty.

Could anyone check what's wrong?

I had tested it on:

\`\`\`
apt update \| grep "NO\_PUBKEY"
\`\`\`

Dear Mcgiwer,

is the command you tried to run

    $ apt update | grep "NO_PUBKEY" > file.txt

?

In this case, the redirection mechanism was working like expected: what you are redirecting is the output of the last command, not of the whole pipeline. So the warnings printed on stderr by apt will never be redirected and will appear in your console.

If you want to redirect the collective output of all commands in a pipeline you can use

    $ { cmd1 | cmd2 ; } > file.txt

Regards,

--
Gioele Barabucci

Reply via email to