submitted 2 years ago* (last edited 2 years ago) by to c/linux@lemmy.ml
 

Can someone explain why this would make the command wait forever? What is tee waiting for?

echo "test" | sudo tee newfile

What would be a scriptable workaround for such cases?

Edit: this command would not terminate in zsh. This works fine in bash tho.

all 17 comments

sorted by: hot top controversial new old
[–] 8 points 2 years ago (6 children)

Can’t reproduce.

16:22:48:~/tmp$ echo foo | sudo tee newfile
[sudo] Passwort für bleistift2:         
foo

16:23:02:~/tmp$ ls -l newfile
-rw-r--r-- 1 root root 4 Feb 23 16:22 newfile
  • source
  • hideshow 6 child comments
  • [–] [S] 3 points 2 years ago (5 children)

    I just switched over to bash and it worked lol. It just didn't return for me in zsh...

  • source
  • parent
  • hideshow 5 child comments
  • [+] 7 points 2 years ago* (last edited 2 years ago)
    [–] 5 points 2 years ago (1 child)

    I'm gonna take a couple of stabs in the dark.

    According to this Stack Overflow answer using tee can prevent the prompt from drawing which makes it appear that a script has not terminated. The answerer's workaround is to put a very short sleep command after the tee command.

    If this is what happened to you maybe the reason the script works in bash but not in zsh is because you have different prompts configured in those two shells.

    Another idea is to replace tee with sponge from moreutils. The difference is that sponge waits for the end of stdin before it starts writing which can avoid problems in some situations.

  • source
  • hideshow 1 child comment
  • [–] 3 points 2 years ago (2 children)

    Why does newfile need sudo to be created?

    You need it to be owned by root?

  • source
  • hideshow 2 child comments
  • [–] 1 point 2 years ago* (3 children)

    Are you saying it waits forever, or you read somewhere it will wait forever and you want clarification?

    Guessing that file doesn't exist already is the problem, and you don't even need to use tee in this example.

  • source
  • hideshow 3 child comments
  • [–] [S] 1 point 2 years ago (2 children)

    what I was saying was that echo "text" | sudo tee newfile would hang and never return and needs to be interrupted. I just noticed this does not happen in bash but I was testing in zsh.

    Guessing that file doesn't exist already is the problem, and you don't even need to use tee in this example.

    you've missed the point here I'm afraid. But I'll blame it on my for not explaining properly what I was intending to do.

  • source
  • parent
  • hideshow 2 child comments