On Mon, Aug 25, 2014 at 11:10:31PM +0800, lolilolicon wrote: > On Mon, Aug 25, 2014 at 8:04 PM, Greg Wooledge <wool...@eeg.ccf.org> 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.
Oh, I see. It's about *protecting* the main script's positional parameters from the sourced script. In that case, the function wrapper seems to be a reasonable solution. Just replace the set -- with shift as others have already suggested. And add a comment describing why you're doing this, so old people like me won't be confused by a function that appears to have no purpose (in 99% of cases).