bug-bash
[Top][All Lists]
Advanced

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

Re: Feature request: Add "import" built-in.


From: lolilolicon
Subject: Re: Feature request: Add "import" built-in.
Date: Mon, 25 Aug 2014 23:10:31 +0800

On Mon, Aug 25, 2014 at 8:04 PM, Greg Wooledge <address@hidden> wrote:
> On Sun, Aug 24, 2014 at 01:36:38PM +0200, Tim Friske wrote:
>> I currently emulate the behavior I seek for with the following function:
>>
>> function _import {
>>   local -r file="$1"
>>   set -- "${@:2}"
>>   source "$file" "$@"
>> }
>
> How is this different from source, exactly?  You're passing all of the
> same arguments.  Your function is identical to:
>
> _import() {
>     source "$@"
> }
>

His function deals with the edge case where there is no argument
passed to the source'd file. He wants `source` to behave the same
inside and outside of a function.

For anyone who wants to test this quickly, try the following code:

    #!/bin/bash

    i() {
      printf '%s:' "$FUNCNAME"
      local -r f=$1
      shift
      . "$f" "$@"
    }

    s() {
      printf '%s:' "$FUNCNAME"
      . "$@"
    }

    printf '%s:' "."
    . ./s.sh
    i ./s.sh
    s ./s.sh

where ./s.sh contains:

    printf '%s:%s\n' $# "$*"

The output:

    % ./test.sh
    .:0:
    i:0:
    s:1:./s.sh



reply via email to

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