This file is source.def, from which is created source.c.
It implements the builtins "." and "source" in Bash.
-Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
+Copyright (C) 1987-2002 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 1, or (at your option) any later
+Software Foundation; either version 2, or (at your option) any later
version.
Bash is distributed in the hope that it will be useful, but WITHOUT ANY
You should have received a copy of the GNU General Public License along
with Bash; see the file COPYING. If not, write to the Free Software
-Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
$PRODUCES source.c
#include <config.h>
#include "../bashtypes.h"
-#include "../posixstat.h"
-#include "../filecntl.h"
+#include "posixstat.h"
+#include "filecntl.h"
#ifndef _MINIX
# include <sys/file.h>
#endif
#include "../shell.h"
#include "../findcmd.h"
#include "common.h"
+#include "bashgetopt.h"
#if !defined (errno)
extern int errno;
/* If non-zero, `.' uses $PATH to look up the script to be sourced. */
int source_uses_path = 1;
+/* If non-zero, `.' looks in the current directory if the filename argument
+ is not found in the $PATH. */
+int source_searches_cwd = 1;
+
/* If this . script is supplied arguments, we save the dollar vars and
replace them with the script arguments for the duration of the script's
execution. If the script does not change the dollar vars, we restore
- what we saved. If the dollar vars are changed in the script, we leave
- the new values alone and free the saved values. */
+ what we saved. If the dollar vars are changed in the script, and we are
+ not executing a shell function, we leave the new values alone and free
+ the saved values. */
static void
maybe_pop_dollar_vars ()
{
- if (dollar_vars_changed ())
- {
- dispose_saved_dollar_vars ();
- set_dollar_vars_unchanged ();
- }
+ if (variable_context == 0 && (dollar_vars_changed () & ARGS_SETBLTIN))
+ dispose_saved_dollar_vars ();
else
pop_dollar_vars ();
+ set_dollar_vars_unchanged ();
}
/* Read and execute commands from the file passed as argument. Guess what.
int result;
char *filename;
+ if (no_options (list))
+ return (EX_USAGE);
+ list = loptend;
+
if (list == 0)
{
builtin_error ("filename argument required");
return (EX_USAGE);
}
- if (no_options (list))
- return (EX_USAGE);
-
#if defined (RESTRICTED_SHELL)
if (restricted && strchr (list->word->word, '/'))
{
- builtin_error ("%s: restricted", list->word->word);
+ sh_restricted (list->word->word);
return (EXECUTION_FAILURE);
}
#endif
if (source_uses_path)
filename = find_path_file (list->word->word);
if (filename == 0)
- filename = savestring (list->word->word);
+ {
+ if (source_searches_cwd == 0)
+ {
+ builtin_error ("%s: file not found", list->word->word);
+ return (EXECUTION_FAILURE);
+ }
+ else
+ filename = savestring (list->word->word);
+ }
begin_unwind_frame ("source");
add_unwind_protect ((Function *)xfree, filename);