bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange behaviour when sourcing files with functions


From: Chet Ramey
Subject: Re: Strange behaviour when sourcing files with functions
Date: Tue, 26 Aug 2003 09:16:15 -0400

> Machine Type: i386-pc-linux-gnu
> 
> Bash Version: 2.05a
> Patch Level: 0
> Release Status: release
> 
> Description:
> 
> In the following '$' symbolizes the bash prompt and we imitate an interactive 
> bash session.
> 
> $ echo '. foo ooh ; echo $1' > fooscript
> $ echo : > foo
> $ bash fooscript aah
> aah
> $ echo 'fnc() { :; } ; fnc' > foo
> $ bash fooscript aah
> ooh
> 
> I find it very strange that the $1 of a script becomes overwitten by a . 
> command. It smells
> like a bug.

I picked this behavior up from ksh.  I assume it was part of Dave Korn's
effort to make functions and `.' behave more similarly.

If additional arguments are supplied to `.' after the filename, they become
the positional parameters while the commands from the file are being read
and executed.  When `.' finishes, the original positional parameters are
restored.  In this respect, the behavior is similar to executing shell
functions.

However, for backwards compatibility, if the commands in the script executed
with `.' manipulate the positional parameters, they persist once the script
completes.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )
                                                Live...Laugh...Love
Chet Ramey, ITS, CWRU    chet@po.CWRU.Edu    http://cnswww.cns.cwru.edu/~chet/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]