1

Can someone explain how this command :

echo "/bin/sh <$(tty) >$(tty) 2>$(tty)" | sudo at now;tail -f /dev/null

starts a root shell but this command :

echo "/bin/sh" | sudo at now; tail -f /dev/null just takes input and does nothing.

I do understand the fact that tail -f /dev/null has the same effect as the second command but what are the factors that make the first command different from the second.

I have posted a similar question : What does " /bin/sh <$(tty) >$(tty) 2>$(tty) " mean? But this question focuses on the difference between the commands mentioned above. Thanks in advance.

4
  • 3
    Does this answer your question? What does " /bin/sh <$(tty) >$(tty) 2>$(tty) " mean?
    – Daniel B
    Commented Oct 8, 2021 at 10:52
  • 1
    Why did you repost the exact same question?
    – Daniel B
    Commented Oct 8, 2021 at 10:52
  • My doubt there was how the tty part works... I kinda understood something from the answer i got. But this question focuses on how just the tty part is giving us a shell. I hope i am clear to you Commented Oct 8, 2021 at 11:00
  • To make myself more clear, my previous question was how echo "/bin/sh <$(tty) >$(tty) 2>$(tty)" | sudo at now;tail -f /dev/null command works. This question focuses how this command is different from the second command. Commented Oct 8, 2021 at 11:03

1 Answer 1

1

It seems to me that they both do the same thing, save for how input and output is handled.

One of the properties of the "at" command is that it launches in a separate tty, this input and output from the tty you type from is ignored. The addition of the redirects forces the at command to read from the specified tty (by redirecting in input and redirecting out stdout and stderr).

To further clarify

$(tty)

Means "run the command tty and make the result part of the command line". tty identifies the terminal of your screen.

< $(tty) 

Is an instruction to pipe input from whatever device $(tty) is. Likewise

> $(tty) 2>($tty)

Output the results of stderr (the first part), and stderr (2>) to your current terminal.

Thus the command is communicating with your terminal even though asynchronously launched - assuming $(tty) resolves to your current terminal. (You can check the value of your current terminal with the command "echo tty"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .