exit: exit the shell
exit [N]
Examples
$ exitleave this shell: an SSH session closes, a sudo -i / su shell drops back to your own user
$ exit 3leave with status 3 - in a script, the caller sees it in $?
$ bash -c 'exit 3'; echo $?prints 3: the exit status of the child shell
Gotchas
- Ctrl+D on an empty prompt does the same as exit (end of input). In a login shell
logoutworks too. - Without N, exit uses the status of the last command - so
exitstraight after a failed command fails the script. - exit inside a file you
sourcecloses YOUR shell (and an SSH session with it); use return there. - Not a shell prompt? less, man and top quit with q, nano with Ctrl+X, vim with Esc then :q (or :q! to discard). A frozen SSH session: Enter, then ~. closes it from your side.
Taught in
- 20.1 Under kubectl: the nodes are Linux machines
- 35.17 Inside the instance: IMDSv2, instance roles, Session Manager
- 38.1 RDS: a managed PostgreSQL you reach by DNS
- 38.3 Multi-AZ, read replicas and the failover your clients must survive
- 38.15 ElastiCache: when a cache helps, and what happens when it fails over
- 38.17 Block, file and object: EBS, instance store, EFS and when each fits
Try exit in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.