New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sanity Check #1
Comments
I have thought about this also, and experimented a bit. I think a serious language certainly should be able to do this. Though I am unsure whether you wouldn't be creating more pain for your self by treating bash as a serious language though. Btw, I definitely think this is worth experimenting with though! you might be able to do something with subshells to support version conflicts? |
Thanks Dominic:
I think I should quote you on this in the README (if you are ok with that), as it does help set some reasonable expectations of what can be achieved in the BASH environment. Thanks for the heads up on |
@DamonOehlman sure. ANYTHING can be achieved in bash, but can your sanity be preserved? |
You're right, I just don't have that much sanity to be able to afford significant losses. Perhaps our collective sanity, however, can afford to take the hit. I propose that I create an org (see https://github.com/bashinate but a better name is probably required) and invite those willing to risk some sanity to help make BASH a tad more package and require friendly. Long term success being the goal, no promises or expectations in the short term. |
@dominictarr @nathan7 you're both invited by the way, but no pressure to accept or do anything. |
@DamonOehlman I've got an idea how to make modular bash with subshells. Basically you want to write your module "module-aware": ## inside module 'foo'
foo_bar() {
echo "hello, ${1}!"
}
module export foo_bar as bar What Then, in your program: import foo
foo bar user # -> hello, user! You could also do it like this:
The benefit from this is that it's stupidly simple to use and completely modular. The drawbacks are:
P.S. We can also go further and add some special pseudo-syntax to access modules: import foo
foo.bar username
# or...
foo::bar username
# or...
foo_bar username
# etc. |
oh btw, I'm not sure what @stylemistake is intending as implementation, but I often do something similar in bash, to make commands # foobar.sh
foo () {
echo foo
}
bar () {
echo bar
}
if [ "$0" = "$BASH_SOURCE" ]; then
"$@"
fi so running |
@dominictarr safer alternative: case ${1} in
'bar') shift; foo_bar "${@}" ;;
esac or # didn't test this, but you get the idea
declare -A exports=(
[bar]=foo_bar
)
name="${1}"
fn="${exports[$name]}"
shift
[[ -n "${fn}" ]] "${fn}" "${@}" This is incompatible with bash-3.x tho, but it must die anyway ( |
the point of coding in bash is that it is already everywhere, if you are requiring a specific version of bash, you might as well just use well... any of the programming languages you use when you have a choice about which programming language you can use. |
Proof of concept: https://github.com/stylemistake/bash-module |
@stylemistake if modules arn't singletons then you don't have version conflicts. node.js has non singleton modules and it works great! (i wish another language was like that) |
@dominictarr making it work like require in node.js would be perfect. |
👍 sounds awesome to me :) |
Closing - though still unsure about my sanity. Haven't done too much recently with this, but if others have achieved anything interesting in the land of BASH then I'm keen to know :) |
@dominictarr @substack @rvagg @hughsk - Just looking for a quick sanity check as to whether this is a (semi) sensible thing to do. There are lots of problems with the approach (no isolation of packages, versions will currently clobber each other etc).
I've thought about this before though when I played around with a pure BASH based way of attempting to provision a machine, but shied away from it. I've published this one package to npm, but I'm going to hold off publishing any more until the general concept has been peer reviewed.
Be brutal, I'm quite ok if this goes nowhere, and if brutality makes it good then that's awesome :)
The text was updated successfully, but these errors were encountered: