You’re not forced into global forced variables, but they’re the default. Use the local keyword in front of the variable declaration for nicely scoped variable.
It’s not that cumbersome to do things like
localdate=`date`
echo"$date"
but in all honesty the syntax sucks ass because it’s not intuitive. If statements suck ass, passing variables has to be done via command line arguments sucks ass, switch statements suck ass, making structured data sucks ass (jq is nice though).
I agree with you that bash really sucks when you get to anything more than 10 lines and at that point I’d take literally prefer Dreamberd.
I didn’t mean that bash has no local variables, but rather that if you want to use a function as such without capturing stdout, you need variables that are scoped across your functions, which is usually global or at least effectively global.
Turns out you can, by using () instead of {} in the function declaration you can run the function in a subshell where changes to variables are scoped to the subshell and functions are local.
You’re not forced into global forced variables, but they’re the default. Use the
localkeyword in front of the variable declaration for nicely scoped variable.It’s not that cumbersome to do things like
local date=`date` echo "$date"but in all honesty the syntax sucks ass because it’s not intuitive. If statements suck ass, passing variables has to be done via command line arguments sucks ass, switch statements suck ass, making structured data sucks ass (
jqis nice though).I agree with you that bash really sucks when you get to anything more than 10 lines and at that point I’d take literally prefer Dreamberd.
I didn’t mean that bash has no local variables, but rather that if you want to use a function as such without capturing stdout, you need variables that are scoped across your functions, which is usually global or at least effectively global.
Turns out you can, by using () instead of {} in the function declaration you can run the function in a subshell where changes to variables are scoped to the subshell and functions are local.
vomits