Hacker News new | ask | show | jobs
by jamescun 3678 days ago
What is the benefit of this over the `source` builtin?

    source bye.sh
or

    . bye.sh
1 comments

better management of your dependencies, also bundling to single file for easier distribution. In future transforming scripts with plugins means reusing fish shell functions in bash scripts .etc Also each shell has different syntax for sourcing files.
If you're needing to manage dependencies for a bash script, are you sure you're using the right language for the job? I'm not convinced that mixing and matching functions from different shells is a good thing.
I like to modularise my shell scripts for maintainability reasons. It would be nice to be able to just "pull in the pieces" as needed from my collection of components instead of, as I currently tend to do, re-including them wherever I'm using them.
I guess I'm having trouble seeing the use-case for having large enough shell scripts to require splitting them up into modules.

What types of functions do you write in shell that you need to re-import?

How is this not achievable by the source builtin?

It's perfectly feasible to have small bash scripts, library functions of sorts, and source them in the script you want to use them in.

At that point why not just use a battle-tested config management tool? Ansible, salt, chef, puppet...