Discussion:
feature request: source a script with executing anything
(too old to reply)
Patrick Schleizer
2018-07-25 10:44:00 UTC
Permalink
For example /usr/bin/xdg-open has some functions (search_desktop_file,
get_key) that look fine that I don't want to copy/paste [1] [2] in my
script.

feature request:

I would like to have a feature to tell bash "source --no-exec
/usr/bin/xdg-open" or so which ignores all commands outside of shell
functions and just imports the shell functions from /usr/bin/xdg-open.

Cheers,
Patrick

[1] avoids attributing copyright
[2] avoids duplicate code
Greg Wooledge
2018-07-25 12:02:40 UTC
Permalink
Post by Patrick Schleizer
I would like to have a feature to tell bash "source --no-exec
/usr/bin/xdg-open" or so which ignores all commands outside of shell
functions and just imports the shell functions from /usr/bin/xdg-open.
It wouldn't really work. Bash functions are not always "pure" standalone
things that can be used in isolation.

Just *one* example: the parser must be told, in advance, whether the
function definition will need to be parsed with extglob turned on. So,
not only would you need to "source" the function definition, but also
any prior shopt commands.

And then, what if the shopt command has a list of options stored in an
array variable? You'd need the code that sets that array variable.

And so on.
Chet Ramey
2018-07-25 18:47:52 UTC
Permalink
Post by Patrick Schleizer
For example /usr/bin/xdg-open has some functions (search_desktop_file,
get_key) that look fine that I don't want to copy/paste [1] [2] in my
script.
This is a good argument for recommending that xdg-open use function
libraries, but I don't see a compelling argument for including this
functionality in bash.

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU ***@case.edu http://tiswww.cwru.edu/~chet/
Loading...