Skip to main content
deleted 5 characters in body
Source Link
ilkkachu
  • 148.2k
  • 16
  • 268
  • 441

You also can't use /dev/stdout here, since that will point to the pipeline. One way might be to take a copy of the script's original stdout, and have tee print into that (I didn't test this):

exec 9>&1 # make fd 9 a copy of the current stdout apt full-upgrade -y | tee /dev/fd/9 | grep linux-headers exec 9>&- # close fd 9 

If you wanted the full output to always go to a terminal, you could use /dev/tty:

apt full-upgrade -y | tee /dev/tty | grep linux-headers 

but that would make the output go to the terminal regardless of what redirections are applied to the whole script.


In some cases, could also use process substitution to redirect the output to a command in addition to stdout:

apt full-upgrade -y | tee >(grep linux-headers) 

but this doesn't really work here since you need the exit status of grep and the process substitution doesn't make it easy to get it.

You also can't use /dev/stdout here, since that will point to the pipeline. One way might be to take a copy of the script's original stdout, and have tee print into that (I didn't test this):

exec 9>&1 # make fd 9 a copy of the current stdout apt full-upgrade -y | tee /dev/fd/9 | grep linux-headers exec 9>&- # close fd 9 

If you wanted the full output to always go to a terminal, you could use /dev/tty:

apt full-upgrade -y | tee /dev/tty | grep linux-headers 

but that would make the output go to the terminal regardless of what redirections are applied to the whole script.


In some cases, could also use process substitution to redirect the output to a command in addition to stdout:

apt full-upgrade -y | tee >(grep linux-headers) 

but this doesn't really work here since you need the exit status of grep and the process substitution doesn't make it easy to get it.

You can't use /dev/stdout here, since that will point to the pipeline. One way might be to take a copy of the script's original stdout, and have tee print into that (I didn't test this):

exec 9>&1 # make fd 9 a copy of the current stdout apt full-upgrade -y | tee /dev/fd/9 | grep linux-headers exec 9>&- # close fd 9 

If you wanted the full output to always go to a terminal, you could use /dev/tty:

apt full-upgrade -y | tee /dev/tty | grep linux-headers 

but that would make the output go to the terminal regardless of what redirections are applied to the whole script.


In some cases, could also use process substitution to redirect the output to a command in addition to stdout:

apt full-upgrade -y | tee >(grep linux-headers) 

but this doesn't really work here since you need the exit status of grep and the process substitution doesn't make it easy to get it.

Source Link
ilkkachu
  • 148.2k
  • 16
  • 268
  • 441

You also can't use /dev/stdout here, since that will point to the pipeline. One way might be to take a copy of the script's original stdout, and have tee print into that (I didn't test this):

exec 9>&1 # make fd 9 a copy of the current stdout apt full-upgrade -y | tee /dev/fd/9 | grep linux-headers exec 9>&- # close fd 9 

If you wanted the full output to always go to a terminal, you could use /dev/tty:

apt full-upgrade -y | tee /dev/tty | grep linux-headers 

but that would make the output go to the terminal regardless of what redirections are applied to the whole script.


In some cases, could also use process substitution to redirect the output to a command in addition to stdout:

apt full-upgrade -y | tee >(grep linux-headers) 

but this doesn't really work here since you need the exit status of grep and the process substitution doesn't make it easy to get it.