1 This file is exit.def, from which is created exit.c.
2 It implements the builtins "exit" and "logout" in Bash.
4 Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
6 This file is part of GNU Bash, the Bourne Again SHell.
8 Bash is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 1, or (at your option) any later
13 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License along
19 with Bash; see the file COPYING. If not, write to the Free Software
20 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 $FUNCTION exit_builtin
27 Exit the shell with a status of N. If N is omitted, the exit status
28 is that of the last command executed.
32 #include <sys/types.h>
36 #include "builtext.h" /* for jobs_builtin */
38 extern int interactive, login_shell;
39 extern int last_command_exit_value;
41 static int exit_or_logout ();
42 static int sourced_logout = 0;
50 fprintf (stderr, login_shell ? "logout\n" : "exit\n");
54 return (exit_or_logout (list));
58 $FUNCTION logout_builtin
60 Logout of a login shell.
68 if (!login_shell && interactive)
70 builtin_error ("Not login shell: use `exit'");
71 return (EXECUTION_FAILURE);
74 return (exit_or_logout (list));
77 /* Clean up work for exiting or logging out. */
78 Function *last_shell_builtin = (Function *)NULL;
79 Function *this_shell_builtin = (Function *)NULL;
87 #if defined (JOB_CONTROL)
88 int exit_immediate_okay;
90 exit_immediate_okay = (!interactive ||
91 last_shell_builtin == exit_builtin ||
92 last_shell_builtin == logout_builtin ||
93 last_shell_builtin == jobs_builtin);
95 /* Check for stopped jobs if the user wants to. */
96 if (!exit_immediate_okay)
99 for (i = 0; i < job_slots; i++)
100 if (jobs[i] && (jobs[i]->state == JSTOPPED))
102 fprintf (stderr, "There are stopped jobs.\n");
104 /* This is NOT superfluous because EOF can get here without
105 going through the command parser. Set both last and this
106 so that either `exit', `logout', or ^D will work to exit
107 immediately if nothing intervenes. */
108 this_shell_builtin = last_shell_builtin = exit_builtin;
109 return (EXECUTION_FAILURE);
112 #endif /* JOB_CONTROL */
114 /* Get return value if present. This means that you can type
115 `logout 5' to a shell, and it returns 5. */
117 exit_value = get_numeric_arg (list);
119 exit_value = last_command_exit_value;
121 /* Run our `~/.bash_logout' file if it exists, and this is a login shell. */
122 if (login_shell && sourced_logout++ == 0)
123 maybe_execute_file ("~/.bash_logout", 1);
125 last_command_exit_value = exit_value;
127 /* Exit the program. */
128 longjmp (top_level, EXITPROG);