News for hackers. Stuff that matters.
Re:Something about functions in Bash (2017) by badloginagain on Thursday July 05, 2018 @07:22PM (#17467715)
Shellcheck is one of those rare tools that made me a significantly better developer. In part because the more bash a dev knows the more effective they are at life in general, in part because it made it easy to follow rigorous coding standards- allowing me to take the quality-code mindset to less rigorous environments.
Re:Something about functions in Bash (2017) by flukus on Thursday July 05, 2018 @08:54PM (#17468133)
> In part because the more bash a dev knows the more effective they are at life in general

On that note this article (https://iridakos.com/tutorials/2018/03/01/bash-programmable-...) on bash completion scripts has been a big boon for my effectiveness recently. I've been creating simulations of our complex interactions with third party systems and the completions scripts are doing things like pulling the correct values from the database rather than having to type them in manually.

I knew I'd saved a bunch of time but it really hit home yesterday when I had to explain to QA how to repeat the process and it's "open this file, change these values, save it here, open other file, set these values from previous file, save here". For me the whole thing is "cmd<tab><tab>".

Does anyone have any tips on taking scripts like that and generalizing them for whole teams? At the moment they're very much built for my personal needs.

Re:Something about functions in Bash (2017) by cwilkes on Friday July 06, 2018 @09:36AM (#17471254)
If you can move them over to a slackbot and direct people to a slack channel to use it. Then you get the benefit of * everyone using the latest version * a history of commands run. People can then use it as a built in FAQ and see what to do based on what others do * they don’t have to have any software installed locally

Of course it doesn’t work for everything but if you can try it out.

Re:Something about functions in Bash (2017) by 3rdAccount on Thursday July 05, 2018 @10:55PM (#17468525)
Usually I just add the script to our wiki (Confluence/Jira) with background information and usage examples. Then I export as a PDF copy for those without access.
Re:Something about functions in Bash (2017) by sethrin on Thursday July 05, 2018 @08:32PM (#17468043)
I wrote a short book for novices on shell usage, because it is extremely important for developers to know. Bash one-liners are usually even pretty defensible. But I dream about how the world would be if Bash were actually a good scripting language. It compares favorably to csh, and I fear that's about the best you can say for it.
Re:Something about functions in Bash (2017) by AceJohnny2 on Thursday July 05, 2018 @10:00PM (#17468374)
> But I dream about how the world would be if Bash were actually a good scripting language. It compares favorably to csh, and I fear that's about the best you can say for it.

I finally started appreciating Perl after having to write some nontrivial Bash scripts.

(My hierarchy is: default to Bash when my task is mostly running commands. If there's a bit of text-processing or regex required, Perl. If I need any hierarchical datastructures, Python)

Re:Something about functions in Bash (2017) by sethrin on Thursday July 05, 2018 @10:30PM (#17468445)
I think that the simple expression of this might be that Bash is a command language, not a scripting language.
Re:Something about functions in Bash (2017) by ryl00 on Friday July 06, 2018 @02:15AM (#17469332)
What's difficult about hierarchial data structures in Perl?
Re:Something about functions in Bash (2017) by vgy7ujm on Friday July 06, 2018 @05:28AM (#17470061)
Agreed, it's rather one of Perl's strengths.
Re:Something about functions in Bash (2017) by AceJohnny2 on Friday July 06, 2018 @03:30PM (#17474406)
The need for references.
Re:Something about functions in Bash (2017) by 3rdAccount on Thursday July 05, 2018 @10:52PM (#17468515)
Haha, I came to the same conclusions. Perl can do nested data structures, but it ain't easy. With Python, I did it without knowing it was a thing.
Re:Something about functions in Bash (2017) by nerdponx on Thursday July 05, 2018 @10:35PM (#17468463)
You might enjoy Zsh.
Re:Something about functions in Bash (2017) by MaxBarraclough on Friday July 06, 2018 @05:37AM (#17470105)
> It compares favorably to csh, and I fear that's about the best you can say for it.

Ha. Talk about 'damned with faint praise'.

I'm not really in the Unix admin world, but can't you just bite the bullet and use a 'real scripting language' like Python? Other than for things like configure scripts, is the universality of BASH/POSIX really non-negotiable?

Re:Something about functions in Bash (2017) by jacobush on Friday July 06, 2018 @08:08AM (#17470719)
Python has versions
Re:Something about functions in Bash (2017) by MaxBarraclough on Friday July 06, 2018 @10:45AM (#17471784)
Python3 is pretty stable, no?
Re:Something about functions in Bash (2017) by jacobush on Friday July 06, 2018 @10:53AM (#17471876)
It's starting to get there, recently, so I am hopeful Python can be a good alternative to Bash more often nowadays!

There is also the cultural difference. In Python, it's so easy use pip and modules, but if you want something to replace Bash, you need to resist the temptation and only use what's in the standard library. The thing with Bash scripts is that they are often self contained and you can grab a huge snippet of it and it will work pretty much everywhere. (Exceptions of course, the script may do some fancy include or use a program not available, but you get my drift with this.)

Bash has been stable a long time, and the Bourne shell compatible part of it for even longer.

Re:Something about functions in Bash (2017) by vageli on Saturday July 07, 2018 @12:36PM (#17479241)
> There is also the cultural difference. In Python, it's so easy use pip and modules, but if you want something to replace Bash, you need to resist the temptation and only use what's in the standard library.

I don't think it's fair to say that bash programs are not without dependencies, just that the developers (tended to be?) are more thoughtful about portability. For example I've seen scripts that use wget or fall back to curl when it's not available. I've never seen a python script fall back to urllib3 when requests wasn't available on the system.

Re:Something about functions in Bash (2017) by jacobush on Monday July 09, 2018 @05:07AM (#17488901)
Well, culture. Python could be programmed to fallback to urllib3. Bash could have a package manager and virtual environments.

Hm... I wonder if that is a good idea or a horrible one... :)

Re:Something about functions in Bash (2017) by jonnydubowsky on Friday July 06, 2018 @12:42AM (#17468885)
I'd love to know more about the book!
Re:Something about functions in Bash (2017) by sethrin on Saturday July 07, 2018 @02:37AM (#17477387)
The focus is on usage as opposed to scripting, and it was written in a few days as a somewhat visceral reaction to seeing a single-page introduction to the shell in a coding academy. It may be that the term "booklet" is more appropriate than "book", and it is certainly the case that "wrote" in the context above should not imply "edited" or "published". However, at the moment I am between projects, and I am very happy to take your interest as a spur to complete this work. However, if you had some time to indulge, I might be able to repay your interest somewhat sooner; having other people review one's final copy is probably the next thing to a necessity.
Re:Something about functions in Bash (2017) by yAnonymous on Friday July 06, 2018 @05:06AM (#17469981)
>In part because the more bash a dev knows the more effective they are at life in general

At some point, using bash isn't effective anymore. It's great and all, but an important skill is knowing when to use it and when not to.

Re:Something about functions in Bash (2017) by amelius on Friday July 06, 2018 @06:47AM (#17470348)
Totally agree. I'm using bash only for scripts that are at most (say) 10 lines long. More complicated than that, and I'm off to a real programming language.