[Top][All Lists]

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

Re: [Help-bash] Inconsistency of the behavior of `source` with and witho

From: Chet Ramey
Subject: Re: [Help-bash] Inconsistency of the behavior of `source` with and without arguments in function
Date: Wed, 22 Jul 2015 09:51:18 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.7.0

On 7/17/15 8:51 PM, Peng Yu wrote:
> Hi, The following code shows that $@ is treated differently when
> `source` is used with and without arguments in `function`. Isn't it
> better to make `source` always pass "$@" from the source script back
> to the external script whether arguments are used with `source` or
> not?

This was a conscious decision.  `source' will temporarily set the
positional parameters from arguments following the filename, so sourced
files can be a little closer to scripts or shell functions.  However,
since `source' is supposed to act as if the commands it executes were
entered directly, changes to the positional parameters made within the
sourced file persist.  It has been this way for a very long time, back
to the bash-1.x days.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden

reply via email to

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