builtin

logout — exit login shell

Ends a login shell with the given status (or the previous status if omitted); in a non-login shell it fails. Unlike exit, logout requires login mode. Test in disposable child shells with startup files disabled, never in the current personal shell. Run in a fresh private directory with HOME set to that directory and LC_ALL=C. Expected output (one item per line): login status=7; non-login status=1.

Formal Syntax & Structure

bash syntaxbash
logout [status]

Parameters & Attributes

NameTypeDescription
statusintegerRequested exit status.

Return Value

exit status

Returns zero on success and nonzero on failure; option queries return zero when enabled.

Working Example

Example Snippetbash
if bash --noprofile --norc -l -c 'logout 7'; then exit 1; else printf 'login status=%s\n' "$?"; fiif bash --noprofile --norc -c 'logout 7' 2> diagnostic; then exit 1; else printf 'non-login status=%s\n' "$?"; fi
Bash Reference