#include <signal.h>
#include <errno.h>
#include "filecntl.h"
-#include <pwd.h>
+#if defined (HAVE_PWD_H)
+# include <pwd.h>
+#endif
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#if defined (JOB_CONTROL)
#include "jobs.h"
+#else
+extern int initialize_job_control __P((int));
+extern int get_tty_state __P((void));
#endif /* JOB_CONTROL */
#include "input.h"
This is a superset of the information provided by interactive_shell.
*/
int startup_state = 0;
+int reading_shell_script = 0;
/* Special debugging helper. */
int debugging_login_shell = 0;
#if defined (RESTRICTED_SHELL)
{ "restricted", Int, &restricted, (char **)0x0 },
#endif
- { "verbose", Int, &echo_input_at_read, (char **)0x0 },
+ { "verbose", Int, &verbose_flag, (char **)0x0 },
{ "version", Int, &do_version, (char **)0x0 },
#if defined (WORDEXP_OPTION)
{ "wordexp", Int, &wordexp_only, (char **)0x0 },
xtrace_init ();
#if defined (USING_BASH_MALLOC) && defined (DEBUG) && !defined (DISABLE_MALLOC_WRAPPERS)
-# if 1
- malloc_set_register (1);
-# endif
+ malloc_set_register (1); /* XXX - change to 1 for malloc debugging */
#endif
check_dev_tty ();
/* Find full word arguments first. */
arg_index = parse_long_options (argv, arg_index, argc);
-
+
if (want_initial_help)
{
show_shell_usage (stdout, 1);
exit (EXECUTION_SUCCESS);
}
+ echo_input_at_read = verbose_flag; /* --verbose given */
+
/* All done with full word options; do standard shell option parsing.*/
this_command_name = shell_name; /* for error reporting */
arg_index = parse_shell_options (argv, arg_index, argc);
}
this_command_name = (char *)NULL;
- cmd_init(); /* initialize the command object caches */
-
/* First, let the outside world know about our interactive status.
A shell is interactive if the `-i' flag was given, or if all of
the following conditions are met:
set_default_locale_vars ();
/*
- * M-x term -> TERM=eterm EMACS=22.1 (term:0.96) (eterm)
- * M-x shell -> TERM=dumb EMACS=t (no line editing)
- * M-x terminal -> TERM=emacs-em7955 EMACS= (line editing)
+ * M-x term -> TERM=eterm-color INSIDE_EMACS='251,term:0.96' (eterm)
+ * M-x shell -> TERM='dumb' INSIDE_EMACS='25.1,comint' (no line editing)
+ *
+ * Older versions of Emacs may set EMACS to 't' or to something like
+ * '22.1 (term:0.96)' instead of (or in addition to) setting INSIDE_EMACS.
+ * They may set TERM to 'eterm' instead of 'eterm-color'. They may have
+ * a now-obsolete command that sets neither EMACS nor INSIDE_EMACS:
+ * M-x terminal -> TERM='emacs-em7955' (line editing)
*/
if (interactive_shell)
{
- char *term, *emacs;
+ char *term, *emacs, *inside_emacs;;
+ int emacs_term, in_emacs;
term = get_string_value ("TERM");
emacs = get_string_value ("EMACS");
+ inside_emacs = get_string_value ("INSIDE_EMACS");
+
+ if (inside_emacs)
+ {
+ emacs_term = strstr (inside_emacs, ",term:") != 0;
+ in_emacs = 1;
+ }
+ else if (emacs)
+ {
+ /* Infer whether we are in an older Emacs. */
+ emacs_term = strstr (emacs, " (term:") != 0;
+ in_emacs = emacs_term || STREQ (emacs, "t");
+ }
+ else
+ in_emacs = emacs_term = 0;
/* Not sure any emacs terminal emulator sets TERM=emacs any more */
no_line_editing |= STREQ (term, "emacs");
- no_line_editing |= emacs && emacs[0] == 't' && emacs[1] == '\0' && STREQ (term, "dumb");
- no_line_editing |= get_string_value ("INSIDE_EMACS") != 0;
+ no_line_editing |= in_emacs && STREQ (term, "dumb");
/* running_under_emacs == 2 for `eterm' */
- running_under_emacs = (emacs != 0) || STREQN (term, "emacs", 5);
- running_under_emacs += STREQN (term, "eterm", 5) && emacs && strstr (emacs, "term");
+ running_under_emacs = in_emacs || STREQN (term, "emacs", 5);
+ running_under_emacs += emacs_term && STREQN (term, "eterm", 5);
if (running_under_emacs)
gnu_error_format = 1;
}
#endif
+ cmd_init (); /* initialize the command object caches */
+ uwp_init ();
+
if (command_execution_string)
{
arg_index = bind_args (argv, arg_index, argc, 0);
arg_index++;
}
else if (interactive == 0)
- /* In this mode, bash is reading a script from stdin, which is a
- pipe or redirected file. */
+ {
+ /* In this mode, bash is reading a script from stdin, which is a
+ pipe or redirected file. */
#if defined (BUFFERED_INPUT)
- default_buffered_input = fileno (stdin); /* == 0 */
+ default_buffered_input = fileno (stdin); /* == 0 */
#else
- setbuf (default_input, (char *)NULL);
+ setbuf (default_input, (char *)NULL);
#endif /* !BUFFERED_INPUT */
+ read_from_stdin = 1;
+ }
+ else if (arg_index == argc)
+ /* "If there are no operands and the -c option is not specified, the -s
+ option shall be assumed." */
+ read_from_stdin = 1;
set_bash_input ();
/* Bind remaining args to $1 ... $n */
arg_index = bind_args (argv, arg_index, argc, 1);
- if (debugging_mode && locally_skip_execution == 0 && running_setuid == 0 && (dollar_vars[1] || interactive_shell == 0))
+ if (debugging_mode && locally_skip_execution == 0 && running_setuid == 0 && (reading_shell_script || interactive_shell == 0))
start_debugger ();
/* Do the things that should be done only for interactive shells. */
#if defined (MALLOC_DEBUG) && defined (USING_BASH_MALLOC)
if (malloc_trace_at_exit)
trace_malloc_stats (get_name_for_error (), (char *)NULL);
+ /* mlocation_write_table (); */
#endif
exit (s);
r = force_execute_file (DEBUGGER_START_FILE, 1);
if (r < 0)
{
- internal_warning ("cannot start debugger; debugging mode disabled");
- debugging_mode = function_trace_mode = 0;
+ internal_warning (_("cannot start debugger; debugging mode disabled"));
+ debugging_mode = 0;
}
- else
- function_trace_mode = 1;
+ error_trace_mode = function_trace_mode = debugging_mode;
+
+ set_shellopts ();
+ set_bashopts ();
exit_immediately_on_error += old_errexit;
#endif
{
e = errno;
file_error (filename);
- exit ((e == ENOENT) ? EX_NOTFOUND : EX_NOINPUT);
+ sh_exit ((e == ENOENT) ? EX_NOTFOUND : EX_NOINPUT);
+ }
+
+ free (dollar_vars[0]);
+ dollar_vars[0] = exec_argv0 ? savestring (exec_argv0) : savestring (script_name);
+ if (exec_argv0)
+ {
+ free (exec_argv0);
+ exec_argv0 = (char *)NULL;
}
if (file_isdir (filename))
errno = EINVAL;
#endif
file_error (filename);
- exit (EX_NOINPUT);
- }
-
- free (dollar_vars[0]);
- dollar_vars[0] = exec_argv0 ? savestring (exec_argv0) : savestring (script_name);
- if (exec_argv0)
- {
- free (exec_argv0);
- exec_argv0 = (char *)NULL;
+ sh_exit (EX_NOINPUT);
}
#if defined (ARRAY_VARS)
{
e = errno;
if ((fstat (fd, &sb) == 0) && S_ISDIR (sb.st_mode))
- internal_error (_("%s: is a directory"), filename);
+ {
+#if defined (EISDIR)
+ errno = EISDIR;
+ file_error (filename);
+#else
+ internal_error (_("%s: Is a directory"), filename);
+#endif
+ }
else
{
errno = e;
init_interactive_script ();
free (filename);
+
+ reading_shell_script = 1;
return (fd);
}
{
expand_aliases = interactive_shell = startup_state = 1;
interactive = 1;
+#if defined (HISTORY)
+ remember_on_history = enable_history_list = 1; /* XXX */
+#endif
}
static void
{
init_noninteractive ();
expand_aliases = interactive_shell = startup_state = 1;
+#if defined (HISTORY)
+ remember_on_history = enable_history_list = 1; /* XXX */
+#endif
}
void
current_user.shell = savestring ("/bin/sh");
current_user.home_dir = savestring ("/");
}
+#if defined (HAVE_GETPWENT)
endpwent ();
+#endif
}
}
/* XXX - should we set jobs_m_flag to 0 here? */
#if defined (HISTORY)
- bash_history_reinit (0);
+ bash_history_reinit (enable_history_list = 0);
#endif /* HISTORY */
#if defined (RESTRICTED_SHELL)
fprintf (fp, _("Type `%s -c \"help set\"' for more information about shell options.\n"), shell_name);
fprintf (fp, _("Type `%s -c help' for more information about shell builtin commands.\n"), shell_name);
fprintf (fp, _("Use the `bashbug' command to report bugs.\n"));
+ fprintf (fp, "\n");
+ fprintf (fp, _("bash home page: <http://www.gnu.org/software/bash>\n"));
+ fprintf (fp, _("General help using GNU software: <http://www.gnu.org/gethelp/>\n"));
}
}