4

MacOS 14, M3 Pro, default zsh shell

I am trying to find the man page for exit corresponding to this entry on SS64. Using man -a exit loads builtin(1) twice, exit(3) once, and Tcl built-in command exit(n) twice.

Can I access the entry on SS64 linked above locally through Terminal? whatis exit is hard to parse, but I couldn't find anything relevant there.

0

4 Answers 4

8

exit is usually provided by your shell, it is not a separate binary.

You will note that there is no exit binary in either of /bin or /usr/bin, and that the man page for exit pulls up builtin(1), which refers you to the man page for your shell.

For example, I use ksh, this is from the ksh man page:

exit [ n ]
              Causes the shell to exit with the exit status specified by n.  The value will be the least significant 8
              bits of n (if specified) or of the exit status of the last command executed.  An end-of-file will also
              cause the shell to exit, except for an interactive shell that has the ignoreeof option turned on (see
              set below).

The exit builtin in ksh also has its own man page (most builtins in ksh have integrated man pages):

NAME
  exit - exit the current shell

SYNOPSIS
  exit [ options ] [n]

DESCRIPTION
  exit is a shell special built-in that causes the shell that invokes it to exit. Before exiting the shell, if the EXIT
  trap is set it will be invoked.

  If n is given, it will be used to set the exit status.

EXIT STATUS
  The exit status is the least significant eight bits of the value of n (if specified) or of the exit status of the
  preceding command. If exit is invoked inside a trap, the preceding command means the command that invoked the trap.

SEE ALSO
  break(1), return(1)

IMPLEMENTATION
  version         exit (ksh 93u+m) 2021-12-08

You can display the integrated man pages forksh builtins with the --man argument.

7
  • What do I have to enter to get ksh man page for exit? Commented May 17 at 23:57
  • 2
    @DavidAnderson In ksh? You can pass --man to any ksh builtin, and the man page will be displayed if it has one. There's also an autoload function that you can use if you are running ksh u+m that extends man to automatically display the man page of a builtin if it has one. github.com/ksh93/ksh/blob/dev/src/cmd/ksh93/fun/man Commented May 18 at 0:06
  • 1
    @DavidAnderson Not related to the question, but if you are using ksh on macOS, I highly recommend ksh u+m, it fixes many many bugs in the ksh93u+ that Apple ships. Commented May 18 at 0:25
  • 3
    If there were an exit executable, it wouldn't work. It would run in its own process, so it can't make the original shell exit.
    – Barmar
    Commented May 18 at 22:08
  • @Barmar In theory it could do something like kill(getppid(), SIGTERM); Commented May 20 at 6:59
5

For my particular case (using zsh), the documentation I was looking for was found using

man zshbuiltins

exit is detailed there. That snippet found on another post.

3
  • I’ll suggest that you enable zsh’s run-help function.
    – fd0
    Commented May 18 at 5:47
  • @fd0 run-help did not need enabling. which run-help returns aliased to man and behaves identically
    – shea
    Commented May 18 at 19:03
  • 1
    If you have GNU info and that zsh doc in info format installed, you can also do info zsh exit. info manuals have an index and table of contents which makes it easier to look for information than with man pages (especially for a manual the size of zsh's).
    – sch
    Commented May 20 at 6:30
4

The man page on SS64 was written by the site admin, so will not be found on your system. My evidence for this is the page contains a link to a Q&A on Unix & Linux Stack Exchange including the user ID of https://unix.stackexchange.com/users/318114/ss64.

1

The man page reference on SS64 would not be for any version of bash released with macOS. The versions of bash released with macOS have never reached version 4. The variable BASHPID referenced in the exit entry on SS64 is only defined for version 4 and higher of bash.

From an unmodified installation of macOS, you can get information about the bash builtin exit from the following. The version is GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin19).

  • Using the bash builtin help command. An example is given below.

    % bash -c 'help exit'
    exit: exit [n]
        Exit the shell with a status of N.  If N is omitted, the exit status
        is that of the last command executed.
    
  • The man page for bash. Here you will have to page down until you reach exit. Below is an excerpt from man bash.

           exit [n]
                  Cause the shell to exit with a status of n.  If  n  is  omitted,
                  the exit status is that of the last command executed.  A trap on
                  EXIT is executed before the shell terminates.
    
  • Use info bash and navigate to the exit builtin. Below is an excerpt.

    Note: The info command was removed starting with macOS Ventura. See this answer for more information.

    `exit'
              exit [N]
         Exit the shell, returning a status of N to the shell's parent.  If
         N is omitted, the exit status is that of the last command executed.
         Any trap on `EXIT' is executed before the shell terminates.
    

You must log in to answer this question.

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