summaryrefslogtreecommitdiff
path: root/builtins/source.def
diff options
context:
space:
mode:
Diffstat (limited to 'builtins/source.def')
-rw-r--r--builtins/source.def21
1 files changed, 17 insertions, 4 deletions
diff --git a/builtins/source.def b/builtins/source.def
index 2da47a16..f9086f81 100644
--- a/builtins/source.def
+++ b/builtins/source.def
@@ -67,15 +67,20 @@ extern int restricted;
/* 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 ())
+ if (variable_context == 0 && dollar_vars_changed ())
{
dispose_saved_dollar_vars ();
set_dollar_vars_unchanged ();
@@ -117,7 +122,15 @@ source_builtin (list)
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);