News for hackers. Stuff that matters.
Re:Techniques I Use to Create a Great User Experience for Sh... by heresie-dabord on Friday September 13, 2024 @08:37PM (#41536552)
> shell scripts are the wrong solution for anything over ~50 lines of code.

I don't think LOC is the correct criterion.

I do solve many problems with bash and I enjoy the simplicity of shell coding. I even have long bash scripts. But I do agree that shell scripting is the right solution only if

    = you can solve the problem quickly 
    = you don't need data structures
    = you don't need math 
    = you don't need concurrency
Re:Techniques I Use to Create a Great User Experience for Sh... by rbonvall on Friday September 13, 2024 @08:54PM (#41536640)
In my opinion, shell scripting is the right tool when you need to do a lot of calling programs, piping, and redirecting. Such programs end up being cumbersome in "proper" languages.
Re:Techniques I Use to Create a Great User Experience for Sh... by skydhash on Friday September 13, 2024 @09:39PM (#41536828)
If there are already software written to do the stuff and I'm just coordinating them (no other computation other than string manipulation) I'd take bash every day. I would only reach to python if I need to do stuff like manipulating complex data structures or something with heavy logic.
Re:Techniques I Use to Create a Great User Experience for Sh... by sulandor on Saturday September 14, 2024 @05:37AM (#41538634)
"you can do anything not matter how horrible you feel"

but yea, shell is foremost a composition language/environment

Re:Techniques I Use to Create a Great User Experience for Sh... by wuming2 on Saturday September 14, 2024 @12:44AM (#41537525)
~1k lines of bash with recutils for data persistency and dc for simple math. Was not quick to solve for me, custom invoices .fodt to .pdf to email, but I got it done. Shell is the only other scripting language I am familiar with other than Ruby. And I am worse at Ruby.

Sometimes options are limited to what you know already.

Re:Techniques I Use to Create a Great User Experience for Sh... by kragen on Saturday September 14, 2024 @07:15AM (#41539020)
some data structures, math, and some concurrency are just fine in shell scripts. bash has arrays so you can do pretty elaborate data structures. where it falls down is being bug-prone. but some code is useful even if it's buggy
Re:Techniques I Use to Create a Great User Experience for Sh... by wruza on Saturday September 14, 2024 @07:18AM (#41539035)
I enjoy the simplicity of shell coding

You mean, the complexity of shell coding? Any operation that in a regular language is like foo.method(arg) in shell expands into something like ${foo#/&$arg#%} or `tool1 \`tool2 "${foo}"\` bar | xargs -0 baz`.

Re:Techniques I Use to Create a Great User Experience for Sh... by xyzzy4747 on Saturday September 14, 2024 @09:11AM (#41539596)
Exactly, plus there's no compiler or type safety.
Re:Techniques I Use to Create a Great User Experience for Sh... by heresie-dabord on Saturday September 14, 2024 @11:07AM (#41540268)
> in a regular language [...] like foo.method(arg)

Note what you just said: when you want an object with a method that takes a parameter, you find bash too complex.

You gave an example that is not appropriate for bash.

However, bash does have functions. So if you don't need an entire underlying object system just to run your logic, you could have

    function foomethod () { 
        parm1=$1
        #more logic   
    }
Re:Techniques I Use to Create a Great User Experience for Sh... by wruza on Saturday September 14, 2024 @07:51PM (#41544000)
My comment was more about basic string/number ops implemented as cryptic incantations, not functions per se. I regularly write bash. Simple things like trimming, deleting suffix, removing quotes, taking a substring, etc always look like someone is cursing in the code. I can’t remember this afterthought gibberish no matter how many times I write it, so I have to maintain few pages of bash snippets in my obtf.

Be damned the day I decided to write a set of scripts in it rather than looking for a way to make typescript my daily driver, like it is now. Bash “code” “base” is one of the worst programming jokes.