17

When I was entering the command

su > echo  "sachin"

it was asking for a password. When I gave my password, some strange things happened as you can see:

Enter image description here

One more thing: there is another user, Hadoop, on my laptop, but when I do

su > echo "Hadoop"

it says

no passwd entry for Hadoop

What does this mean?

  • the su is the ask for super user permissions, the echo is to print something, echo <text> is to print text, the > is what follows, like, su > echo "sachin" is the same as su sachin, because echo "sachin" returns sachin – OverCoder Oct 4 '14 at 19:38
  • 3
    @Yousef's: No. echo is not executed. it is after the redirection command ">", so it is read as a file name. The rest of argument are passed to su as usual! – Rmano Oct 4 '14 at 19:41
  • 1
    @Yousef's You might be thinking of su $(echo "sachin"). That would do what you're saying. – Eliah Kagan Oct 4 '14 at 19:41
  • hmmmm, so sorry for the wrong info, i was not really sure about it but i tried it and that's what i first figured out, thanks for informing me with the right info – OverCoder Oct 4 '14 at 19:42
30

Ah! Nice puzzle!

Just say "exit", and all your files will be there (and the output you miss in a file called echo).

Explication:

 su > echo user 

is the same as

 su user > echo

So you are starting a (sub)shell with su (switch user) to your user, with all output redirected to a file called echo!

Look:

[romano:~] % cd tmp/dvd-usa-hd 
[romano:~/tmp/dvd-usa-hd] % ls
dvd-usa-hd_01_01.avi
[romano:~/tmp/dvd-usa-hd] % su > echo romano
Password: 
[romano:~/tmp/dvd-usa-hd] % ls
[romano:~/tmp/dvd-usa-hd] % exit
[romano:~/tmp/dvd-usa-hd] % ls
dvd-usa-hd_01_01.avi  echo
[romano:~/tmp/dvd-usa-hd] % cat echo
dvd-usa-hd_01_01.avi
echo
[romano:~/tmp/dvd-usa-hd] % 
  • 13
    Good answer. The key confusing and interesting aspect of this puzzle is that, though we usually supply them at the end (or sometimes the beginning) of a simple command, redirections can actually go anywhere--even between arguments. We see commands like su user > echo all the time, and > echo su user with some frequency, but su > echo user almost never, as there's rarely any practical reason to write a command in such a confusing way. (That such syntax is accepted is occasionally useful when automatically generating commands from a program or script, though.) – Eliah Kagan Oct 4 '14 at 19:45
  • 2
    @EliahKagan yes --- and the confusion here is enhanced by the file name. su > stdout.txt user wouldn't be so tricky... – Rmano Oct 6 '14 at 8:19
  • @EliahKagan Learned! – laike9m Oct 6 '14 at 20:12

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.