13

I don't understand why exit & does not work. Why does it not?

5
  • 3
    dummy question. I'd vote for closing it.
    – poige
    Aug 15, 2013 at 14:03
  • 1
    But people may not find the truth on demand then :(
    – Pedro Ziff
    Aug 15, 2013 at 14:05
  • Dummy truth isn't worth finding, don't worry ;)
    – poige
    Aug 15, 2013 at 14:06
  • 3
    But I am happy I found it, life fulfilled suddenly. :)
    – Pedro Ziff
    Aug 15, 2013 at 14:07
  • 1
    Same reason cd / & "doesn't work"
    – kojiro
    Aug 16, 2013 at 11:20

2 Answers 2

21

I think it works. But probably it doesn't do what you expect.

 $ exit &

Will create a sub-shell process, and make it run as a background job which will just finish right away.

1
  • 12
    In other words, this is the "fake your own death" operator.
    – Kaz
    Aug 15, 2013 at 19:54
17

It does work. & forks the shell, starting a new process (you could think of it as & exit, except of course that syntax actually means something else). exit is a shell built-in that ends the shell process -- in this case the new backgrounded shell.

> exit &
[1] 1709
> ps -p 1709
  PID TTY          TIME CMD
[1]+  Done                    exit

There's your job. It's done. It worked.

You must log in to answer this question.

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