1

I guess I know when there is a pipe (|) the left-side command is executed first and the result is passed to the right-side command of pipe but...

apt update | sudo tee

... how can work that way? there is any "syntactic sugar" involved?

2

when there is a pipe (|) the left-side command is executed first and the result is passed to the right-side command of pipe

Incorrect.

Both processes start off at the same time. So, in your example apt update and sudo tee starts at the same time, and the STDOUT of apt update is passed on the STDIN of sudo tee.

There is no syntactic sugar involved, anonymous pipe (|) is a common (and old) form of IPC in *nix.

FWIW, there's also another form of pipe IPC -- named pipe.

7
  • But... if it both process starts at the same time, then ... the left-side commando should be rejected first as is not authorized (it has no permissions / ownership to do that). Or not? please, elaborate.
    – boctulus
    Jun 17 '19 at 14:30
  • @boctulus apt update should be terminated first because of permission, and that will make sudo tee to exit as well. OTOH, if the right-hand process dies first, the left one will get SIGPIPE when it tries to write to STDOUT and will be terminated unless it handles SIGPIPE.
    – heemayl
    Jun 17 '19 at 14:38
  • But "apt update | sudo tee" works :) in a fresh terminal where a sudoers user is logged. So what? You are incorrect.
    – boctulus
    Jun 17 '19 at 14:55
  • @boctulus I didn't claim that it does not work, i only said which terminates when. Please read carefully.
    – heemayl
    Jun 17 '19 at 14:56
  • 1
    @boctulus The left hand command does not have permission and if you run without being superuser it will fail (unless you have done something weird with permissions of the apt binary). Please add the output in your answer.
    – heemayl
    Jun 17 '19 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.